ping.ps1 - powershell script by ActiveXperts Software
ping.ps1 pings a remote host.
Use ping.ps1 directly from ActiveXperts Network Monitor; in the Manager's 'Monitor' menu, select 'New Check (Script)' and select ping.ps1. Configure the required parameter, or press 'Load a working sample'.
In ActiveXperts Network Monitor, Administrators can use three different scripting languages: Powershell, VBScript and SSH.
ping.ps1 script code
################################################################################# # ActiveXperts Network Monitor PowerShell script, © ActiveXperts Software B.V. # For more information about ActiveXperts Network Monitor, visit the ActiveXperts # Network Monitor web site at http://www.activexperts.com ################################################################################# # Script # Ping.ps1 # Description: # Ping a remote host. Ping is based on ActiveXperts Network Component # Declare Parameters: # 1) strHost (string) - Hostname or IP address of the computer you want to ping # 2) nMaxTimeOut (int) - Timeout in milliseconds # Usage: # .\Ping.ps1 '<hostname | IP>' <Timeout_MSecs> # Sample: # .\Ping.ps1 'www.activexperts.com' 160 ################################################################################# # -- Declare Parameters param( [string]$strHost = '', [int]$numMaxTimeOut ) # -- Use _activexperts.ps1 with common functions . 'C:\Program Files\ActiveXperts\Network Monitor\Scripts\Monitor (ps1)\_activexperts.ps1' ################################################################################# # // --- Main script --- ################################################################################# # -- Clear screen and clear error cls $Error.Clear() # -- Check parameters input if( $strHost -eq '' -or $numMaxTimeOut -eq '' ) { $res = 'UNCERTAIN: Invalid number of parameters - Usage: .\ping.ps1 "<Hostname | IP>" Timeout_MSecs' echo $res exit } # -- Create ICMP object $objIcmp = new-object -comobject AxNetwork.Icmp if( $objIcmp -eq $null ) { $res = 'UNCERTAIN: Failed to load ActiveXperts.Icmp' echo $res exit } # -- Ping $objIcmp.Ping( $strHost, 3000 ) # Maximum. timeout: 3000 ms if( $objIcmp.LastError -ne 0 ) { $res = 'UNCERTAIN: ' + $objIcmp.GetErrorDescription( $objIcmp.LastError ) echo $res exit } # -- Check duration if( $objIcmp.LastDuration -gt $numMaxTimeOut ) { $res = 'ERROR: Request from [' + $strHost + '] timed out, time=[' + $objIcmp.LastDuration + 'ms] (>' + $numMaxTimeOut + 'ms) DATA:' + $objIcmp.LastDuration } else { $res = 'SUCCESS: Reply from ' + $strHost + ', time=[' + $objIcmp.LastDuration + 'ms], TTL=[' + $objIcmp.LastTTL + '] DATA:' + $objIcmp.LastDuration } # -- Print script result echo $res exit ################################################################################# # // --- Catch script exceptions --- ################################################################################# trap [Exception] { $res = 'UNCERTAIN: ' + $_.Exception.Message echo $res exit }