directoryservice-ldapserver.ps1 - powershell script by ActiveXperts Software
directoryservice-ldapserver.ps1 query an LDAP server and match the response.
Use directoryservice-ldapserver.ps1 directly from ActiveXperts Network Monitor; in the Manager's 'Monitor' menu, select 'New Check (Script)' and select directoryservice-ldapserver.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.
directoryservice-ldapserver.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 # Last Modified: ################################################################################# # Script # DirectoryService-LDAPServer.ps1 # Description: # Query an LDAP server and match the response # Declare Parameters: # 1) strServer (string) - Server to send the LDAP query to # 2) strExpected (string) - Expected response # 3) strCredentials (string) - Specify an empty string to use Metwork 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: # Usage: # .\DirectoryService-LDAPServer.ps1 '<Hostname | IP>' '<Expected Value>' '[strCredentials]' # Sample # .\DirectoryService-LDAPServer.ps1 'DOMAIN01' 20 '[strCredentials]' ################################################################################## # -- Declare Parameters param( [string]$strServer = '', [string]$strExpected = '', [string]$strAltCredentials = '' ) # -- 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( $strServer -eq '' -or $strExpected -eq '' ) { $res = 'UNCERTAIN: Invalid number of parameters - Usage: .\DirectoryService-LDAPServer.ps1 "<strServer>" "<strExepected>" "[strCredentials]"' echo $res exit } $objAltCredentials = $null $strExplanation = '' # If alternate credentials are specified, retrieve the alternate login and password from the ActiveXperts global settings if( $strAltCredentials -ne '' ) { # Get the Alternate Credentials object. Function "AxGetCredentials" is implemented in "activexperts.ps1" if( ( AxGetCredentials $strHost $strAltCredentials ([ref]$objAltCredentials) ([ref]$strExplanation) ) -ne $AXSUCCESS ) { echo $strExplanation exit } } # -- Declare local variables by assigning initial value $Dom = 'LDAP://' + $strServer + '/RootDse' $objLDAP = new-object DirectoryServices.DirectoryEntry $Dom $strPath = $objLDAP.Get( 'DefaultNamingContext' ) if( $strPath.contains( $strExpected ) -eq 1 ) { $res = 'SUCCESS: LDAP server was queried, response=[' + $strPath + '] matched string [' + $strExpected + ']' } else { $res = 'ERROR: LDAP server was queried, response=[' + $strPath + '] did not match string [' + $strExpected + ']' } # -- Print script result echo $res ################################################################################# # // --- Catch script exceptions --- ################################################################################# trap [Exception] { $res = 'UNCERTAIN: ' + $_.Exception.Message echo $res exit }