msexchangeserver.ps1 - powershell script by ActiveXperts Software
msexchangeserver.ps1 checks whether MS Exchange Server is running; it checks services, processes and performance counters.
Use msexchangeserver.ps1 directly from ActiveXperts Network Monitor; in the Manager's 'Monitor' menu, select 'New Check (Script)' and select msexchangeserver.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.
msexchangeserver.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: # MsExchangeServer.ps1 # Description: # Checks if the MS Exchange Server is running; it checks the MS Exchange services # and MS Exchange processes # Declare Parameters: # 1) strHost (string) - Hostname or IP address of the server you want to check # 2) strAltCredentials (string, optional) - 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: # .\MsExchangeServer.ps1 '<Hostname | IP>' '<Version>' '[alt-credentials]' # Sample: # .\MsExchangeServer.ps1 'localhost' '2010' ################################################################################# # -- Declare Parameters param( [string]$strHost = '', [string]$strVersion = '', [string]$strAltCredentials = '' ) # -- Use _activexperts.ps1 with common functions . 'C:\Program Files\ActiveXperts\Network Monitor\Scripts\Monitor (ps1)\_activexperts.ps1' ################################################################################# # // --- Private Functions section --- ################################################################################# function getSoftwareInfo( $strVersion, [ref]$lstServices, [ref]$lstProcesses, [ref]$lstPerfCounters ) { # Retrieve services, processes and counters associated to the specific version of the software. Entries that start # with '!' are optional services/processes/counters and are not checked by default. Remove '!' mark to enable monitoring those items. switch( $strVersion ) { '2013' { $lstServices.value = @( @( 'MSExchangeADTopology', 'Microsoft Exchange Active Directory Topology' ), @( 'MSExchangeAntispamUpdate' , 'Microsoft Exchange Anti-spam Update' ), @( '!MSExchangeDiagnostics', 'Microsoft Exchange Diagnostics' ), @( 'MSExchangeEdgeSync', 'Microsoft Exchange EdgeSync' ), @( '!MSExchangeHM', 'Microsoft Exchange Health Manager' ), @( '!MSExchangeMonitoring', 'Microsoft Exchange Monitoring' ), @( '!HostControllerService', 'Microsoft Exchange Search Host Controller' ), @( 'MSExchangeServiceHost', 'Microsoft Exchange Service Host' ), @( 'MSExchangeTransport', 'Microsoft Exchange Transport' ), @( 'MSExchangeTransportLogSearch', 'Microsoft Exchange Transport Log Search' ), @( '', '' ) ) $lstProcesses.value = @( 'Microsoft.Exchange.Directory.TopologyService.exe', 'Microsoft.Exchange.AntispamUpdateSvc.exe', '!Microsoft.Exchange.Diagnostics.Service.exe', 'Microsoft.Exchange.EdgeSyncSvc.exe', '!MSExchangeHMHost.exe', '!Microsoft.Exchange.Monitoring.exe', '!hostcontrollerservice.exe', 'Microsoft.Exchange.ServiceHost.exe', 'MSExchangeTransport.exe', 'MSExchangeTransportLogSearch.exe', '' ) $lstPerfCounters.value = @( @( 'Memory', '', 'Available Bytes', '-gt 104857600' ), @( 'Processor', '_TOTAL', '% Processor Time', '-lt 90' ), @( '', '', '', '' ) ) return $AXSUCCESS } '2010' { $lstServices.value = @( @( 'MSExchangeAB', 'Microsoft Exchange Address Book' ), @( 'MSExchangeADTopology', 'Microsoft Exchange Active Directory Topology' ), @( 'MSExchangeAntispamUpdate', 'Microsoft Exchange Anti-spam Update' ), @( 'MSExchangeEdgeSync', 'Microsoft Exchange EdgeSync' ), @( 'MSExchangeFBA', 'Microsoft Exchange Forms-Based Authentication service' ), @( 'MSExchangeFDS', 'Microsoft Exchange File Distribution' ), @( '!MSExchangeImap4', 'Microsoft Exchange IMAP4' ), @( 'MSExchangeIS', 'Microsoft Exchange Information Store' ), @( 'MSExchangeMailboxAssistants', 'Microsoft Exchange Mailbox Assistants' ), @( 'MSExchangeMailboxReplication', 'Microsoft Exchange Mailbox Replication' ), @( 'MSExchangeMailSubmission', 'Microsoft Exchange Mail Submission' ), @( '!MSExchangeMonitoring', 'Microsoft Exchange Monitoring' ), @( '!MSExchangePop3', 'Microsoft Exchange POP3' ), @( 'MSExchangeProtectedServiceHost', 'Microsoft Exchange Protected Service Host' ), @( '!MSExchangeRepl', 'Microsoft Exchange Replication' ), @( 'MSExchangeRPC', 'Microsoft Exchange RPC Client Access' ), @( 'MSExchangeSA', 'Microsoft Exchange System Attendant' ), @( '!MSExchangeSearch', 'Microsoft Exchange Search Indexer' ), @( 'MSExchangeServiceHost', 'Microsoft Exchange Service Host' ), @( '!MSExchangeThrottling', 'Microsoft Exchange Throttling' ), @( '!MSExchangeTransport', 'Microsoft Exchange Transport' ), @( '!MSExchangeTransportLogSearch', 'Microsoft Exchange Transport Log Search' ), @( '', '' ) ) $lstProcesses.value = @( 'Microsoft.Exchange.AddressBook.Service.exe', 'MSExchangeADTopologyService.exe', 'Microsoft.Exchange.AntispamUpdateSvc.exe', 'Microsoft.Exchange.EdgeSyncSvc.exe', 'ExFBA.exe', 'MSExchangeFDS.exe', 'Microsoft.Exchange.Imap4Service.exe', 'store.exe', 'MSExchangeMailboxAssistants.exe', 'MSExchangeMailboxReplication.exe', 'MSExchangeMailSubmission.exe', '!Microsoft.Exchange.Monitoring.exe', '!Microsoft.Exchange.Pop3Service.exe', 'Microsoft.Exchange.ProtectedServiceHost.exe', 'msexchangerepl.exe', 'Microsoft.Exchange.RpcClientAccess.Service.exe', 'mad.exe', '!Microsoft.Exchange.Search.ExSearch.exe', 'Microsoft.Exchange.ServiceHost.exe', '!MSExchangeThrottling.exe', '!MSExchangeTransport.exe', '!MSExchangeTransportLogSearch.exe', '' ) $lstPerfCounters.value = @( @( 'Memory', '', 'Available Bytes', '-gt 104857600' ), @( 'Processor', '_TOTAL', '% Processor Time', '-lt 90' ), @( '', '', '', '' ) ) return $AXSUCCESS } '2007' { $lstServices.value = @( @( 'msexchangeadtopology', 'Microsoft Exchange Active Directory Topology Service' ), @( 'msexchangeantispamupdate', 'Microsoft Exchange Anti-spam Update' ), @( 'msexchangeedgesync', 'Microsoft Exchange EdgeSync' ), @( 'msexchangefds', 'Microsoft Exchange File Distribution' ), @( 'msexchangeantispamupdate', 'Microsoft Exchange IMAP4' ), @( 'msexchangeis', 'Microsoft Exchange Information Store' ), @( 'msexchangemailsubmission', 'Microsoft Exchange Mail Submission' ), @( 'msexchangemailboxassistants', 'Microsoft Exchange Mailbox Assistants' ), @( '!msexchangemonitoring', 'Microsoft Exchange Monitoring' ), @( '!msexchangepop3', 'Microsoft Exchange POP3' ), @( 'msexchangerepl', 'Microsoft Exchange Replication Service' ), @( 'msexchangesearch', 'Microsoft Exchange Search Indexer' ), @( 'msexchangeservicehost', 'Microsoft Exchange Service Host' ), @( 'msexchangesa', 'Microsoft Exchange System Attendant' ), @( 'msexchangetransport', 'Microsoft Exchange Transport' ), @( 'msexchangetransportlogsearch', 'Microsoft Exchange Transport Log Search' ), @( '','' ) ) $lstProcesses.value = @( , '' ) $lstPerfCounters.value = @( @( 'Memory', '', 'Available Bytes', '-gt 104857600' ), @( 'Processor', '_TOTAL', '% Processor Time', '-lt 90' ), @( '', '', '', '' ) ) return $AXSUCCESS } '2000' { $lstServices.value = @( @( 'resvc', 'Microsoft Exchange Routing Engine' ), @( 'msexchangeis', 'Microsoft Exchange Information Store' ), @( '!msexchangees', 'Microsoft Exchange Event' ), @( 'msexchangesa', 'Microsoft Exchange System Attendant' ), @( 'imap4svc', 'Microsoft Exchange IMAP4' ), @( 'pop3svc', 'Microsoft Exchange POP3' ), @( 'msexchangemta', 'Microsoft Exchange MTA Stacks' ), @( '!w3svc', 'World Wide Web Publishing Service' ), @( '!msexchangesrs', 'Microsoft Exchange Site Replication Service' ), @( '!smtpsvc', 'Simple Mail Transport Protocol (SMTP)' ), @( '!nntpsvc', 'Network News Transport Protocol (NNTP)' ), @( '!iisadmin', 'IIS Admin Service' ), @( '!msexchangemgmt', 'Microsoft Exchange Management' ), @( '!msexchangecoco', 'Microsoft Exchange Connectivity Controller' ), @( '!lme-notes', 'Microsoft Exchange Connector for Lotus Notes(R)' ), @( '!lme-gwise', 'Microsoft Exchange Connector for Novell GroupWise' ), @( '!msexchangedx', 'Microsoft Exchange Directory Synchronization' ), @( '!msexchangegwrtr', 'Microsoft Exchange Router for Novell GroupWise' ), @( '!msexchangechat', 'Microsoft Exchange Chat' ), @( '!msexchangeccmc', 'Microsoft Exchange Connector for Lotus(R) cc;;Mail' ), @( '!msexchangemsmi', 'MS Mail Connector Interchange' ), @( '!msexchangefb', 'MS Schedule+ Free-Busy Connector' ), @( '', '' ) ) $lstProcesses.value = @( , '' ) $lstPerfCounters.value = @( @( 'Memory', '', 'Available Bytes', '-gt 104857600' ), @( 'Processor', '_TOTAL', '% Processor Time', '-lt 90' ) @( '', '', '', '' ) ) return $AXSUCCESS } '5.5' { $lstServices.value = @( ( 'msexchangeis', 'Microsoft Exchange Information Store' ), ( 'msexchangemta', 'Microsoft Exchange MTA Stacks' ), ( 'msexchangesa', 'Microsoft Exchange System Attendant' ), ( '', '' ) ) $lstProcesses.value = @( , '' ) $lstPerfCounters.value = @( ( 'Memory', '', 'Available Bytes', '-gt 104857600' ), ( 'Processor', '_TOTAL', '% Processor Time', '-lt 90' ), ( '', '', '', '' ) ) return $AXSUCCESS } default { $lstServices.value = @( , ( '', '' ) ) $lstProcesses.value = @( , '' ) $lstPerfCounters.value = @( , ( '', '', '', '' ) ) return $AXERROR } } } ################################################################################# # // --- Main script --- ################################################################################# # -- Clear screen and clear error cls $Error.Clear() # -- Validate parameters, return on parameter mismatch if( $strHost -eq '' -or $strVesion -eq '' ) { $res = 'UNCERTAIN: Parameter error - Usage: .\MsActiveDirectory.ps1 "<Hostname | IP>" "<Version>" "[alt-credentials]"' echo $res exit } # -- Declare local variables by assigning an initial value to it $lstServices = $null $lstProcesses = $null $lstPerfCounters = $null $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 } } # Retrieve product processes/services/performance-counters list if( ( getSoftwareInfo $strVersion ([ref]$lstServices) ([ref]$lstProcesses) ([ref]$lstPerfCounters) ) -ne $AXSUCCESS ) { $res = 'ERROR: Version [' + $strVersion + '] is not supported.' echo $res exit } # -- Check services if( ( AxCheckServices $strHost ([ref]$lstServices) $objAltCredentials ([ref]$strExplanation) ) -ne $AXSUCCESS ) { echo $strExplanation exit } # -- Check processes if( ( AxCheckProcesses $strHost ([ref]$lstProcesses) $objAltCredentials ([ref]$strExplanation) ) -ne $AXSUCCESS ) { echo $strExplanation exit } # -- Check performance counters if( ( AxCheckPerfCounters $strHost ([ref]$lstPerfCounters) $objAltCredentials ([ref]$strExplanation) ) -ne $AXSUCCESS ) { echo $strExplanation exit } # -- Print script result $res = 'SUCCESS: All services, processes and counters successfully checked' echo $res exit ################################################################################# # // --- Catch script exceptions --- ################################################################################# trap [Exception] { $res = 'UNCERTAIN: ' + $_.Exception.Message echo $res exit }