xml.ps1 - powershell script by ActiveXperts Software
xml.ps1 performs a query on an XML source.
Use xml.ps1 directly from ActiveXperts Network Monitor; in the Manager's 'Monitor' menu, select 'New Check (Script)' and select xml.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.
xml.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 # Xml.ps1 # Description: # This function queries cdcatalog.xml for CDs that have more than 12 songs # If there is more than one record, the function is successfull. # Declare Parameters: # 1) strXmlPath - Path to the Xml file. Can be either a URL, or a file system path # Usage: # .\Xml.ps1 '<URL to XML file | XML on Filesystem>' # Sample: # .\Xml.ps1 'http://www.activexperts.com/network-monitor/demopage/cdcatalog.xml' ################################################################################# # -- Declare Parameters param( [string]$strXmlPath = '' ) # -- 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() # -- Validate parameters, return on parameter mismatch if( $strXmlPath -eq '' ) { $res = 'UNCERTAIN: Invalid number of parameters - Usage: .\Xml.ps1 "<URL to XML file | XML on Filesystem>"' echo $res exit } $xmlDoc = new-object -comobject Microsoft.XMLDOM $xmlDoc.async = $false # $xmlDoc echo's when called on so where fetching the result in a dummy variable, or else Network Monitor # won't handle the result correctly $dummy = $xmlDoc.load( $strXmlPath ) $colNodes = $xmlDoc.selectNodes( '/catalog/cd' ) $strCDs = '' foreach( $x in $colNodes ) { if( $strCDs -ne '' ) { $strCDs += ', ' } $strCDs += $x.SelectSingleNode('artist').text + '-' + $x.SelectSingleNode( 'title' ).text } if( $strCDs -ne '' ) { $res = 'SUCCESS: Following CDs were found: [' + $strCDs + ']' } else { $res = 'ERROR: No CDs found' } # -- Print script result echo $res exit ################################################################################# # // --- Catch script exceptions --- ################################################################################# trap [Exception] { $res = 'UNCERTAIN: ' + $_.Exception.Message echo $res exit }