ActiveXperts Network Monitor ships with a powerful set of pre-defined checks. Each individual check has a static number of configuration items. To monitor other items, or to combine monitoring items, you can make use of custom PowerShell checks.
Most of the built-in checks have a PowerShell equivalent, implemented as a PowerShell (.ps1) script file. Out-of-the-box, each PowerShell script monitors the same items as the built-in check. Feel free to modify the script.
To add a new PowerShell-based MsTerminalServer monitoring check, do the following:
- On the 'Monitor menu', open 'New Monitoring Check (Script)' and choose 'New PowerShell Check'. The 'PowerShell Check' dialog box appears;
- In the 'Script File' selection box, select 'MsTerminalServer.ps1';
- In the 'Script Parameters'group box enter the required parameters. You can also load a working sample first by clicking on the 'Click here to load a sample' link.
To customize the above monitoring check, click on the 'Edit button' next to the 'Script File' selection box. Notepad will be launched. You can now make changes to the PowerShell script.

MsTerminalServer.ps1 script source code
# Network Monitor web site at https://www.activexperts.com ################################################################################# # Script: # MsTerminalServer.ps1 # Description: # Checks if Active Directory is running; it checks the AD services and AD processes # Parameters: # 1) strComputer As String - Hostname or IP address of the computer you want to monitor # 2) nMaxActiveSessions As Number - Maximum number of Active Sessions allowed. 0 means: do not check Active Sessions # 3) nMaxInactiveSessions As Number - Maximum number of Inactive Sessions allowed. 0 means: do not check Inactive Sessions # 4) nMaxTotalSessions As Number - Maximum number of Total Sessions allowed. 0 means: do not check Total Sessions # 5) strCredentials As String - Specify an empty string to use Network Monitor service credentials. # To use alternate credentials, enter a server that is defined in Server Credentials table. # (To define Server Credentials, choose Tools->Options->Server Credentials) # Usage: # .\MsTerminalServer.ps1 '<Hostname | IP>' nMaxActiveSessions nMaxInactiveSessions nMaxTotalSessions '<Empty String | Server>' # Sample: # .\MsTerminalServer.ps1 'localhost' 0 0 2 '' ################################################################################# #parameters param ( [string]$strComputer, [int]$nMaxActiveSessions, [int]$nMaxInactiveSessions, [int]$nMaxTotalSessions, [string]$strCredentials ) ###Functions### ###EndFunctions### if ( $strComputer -eq "" ) { $res = "UNCERTAIN: Invalid number of parameters - Usage: .\MsTerminalServer.ps1 '<Hostname | IP>' nMaxActiveSessions nMaxInactiveSessions nMaxTotalSessions '<Empty String | Server>'" echo $res exit } # Create object if ( [string]$strCredentials -ne "" ) { $objNmCredentials = new-object -comobject ActiveXperts.NMServerCredentials $strLogin = $objNmCredentials.GetLogin( $strCredentials ) if ( $strLogin -eq "" ) { $res = "ERROR: No alternate credentials defined for [" + $strCredentials + "]. In the Manager application, select 'Options' from the 'Tools' menu and select the 'Server Credentials' tab to enter alternate credentials" echo $res exit } $strPassword = $objNmCredentials.GetPassword( $strCredentials ) if ( $strPassword -ne "" ) { $strPasswordSecure = ConvertTo-SecureString -string $strPassword -AsPlainText -Force } $objCredentials = new-object -typename System.Management.Automation.PSCredential $strLogin, $strPasswordSecure } #############################Services####################################### if ( [string]$strCredentials -eq "" ) { $objWmi = Get-WmiObject -ComputerName $strComputer -ea SilentlyContinue -Class Win32_PerfFormattedData_TermService_TerminalServices } else { $objWmi = Get-WmiObject -ComputerName $strComputer -ea SilentlyContinue -Class Win32_PerfFormattedData_TermService_TerminalServices -Credential $objCredentials } if ( $objWmi -eq $null ) { if ( [string]$strCredentials -eq "" ) { $objWmi = Get-WmiObject -ComputerName $strComputer -ea SilentlyContinue -Class Win32_PerfRawData_LocalSessionManager_TerminalServices } else { $objWmi = Get-WmiObject -ComputerName $strComputer -ea SilentlyContinue -Class Win32_PerfRawData_LocalSessionManager_TerminalServices -Credential $objCredentials } } if ($objWmi -eq $null) { $res = "UNCERTAIN: Unable to query WMI on computer [" + $strComputer + "]." } if ($nMaxActiveSessions -lt $objWmi.ActiveSessions) { $res = "ERROR: Currently " + $objWmi.ActiveSessions + " active sessions, Maximum allowed: " + $nMaxActiveSessions + "." echo $res exit } if ($nMaxInactiveSessions -lt $objWmi.InactiveSessions) { $res = "ERROR: Currently " + $objWmi.InactiveSessions + " inactive sessions, Maximum allowed: " + $nMaxInactiveSessions + "." echo $res exit } if ($nMaxTotalSessions -lt $objWmi.TotalSessions) { $res = "ERROR: Currently " + $objWmi.TotalSessions + " sessions (Total), Maximum allowed: " + $nMaxTotalSessions + "." echo $res exit } $res = "SUCCESS: Active Sessions: " + $objWmi.ActiveSessions + "; Inactive Sessions: " + $objWmi.InactiveSessions + "; Total Sessions: " + $objWmi.TotalSessions + "." echo $res exit