Posted on: 08/24/2019 Posted by: Jason Comments: 0

The problem

Out of the box, WhatsUp® Gold does not monitor any Windows services. There is a built-in active monitor type called “Service Monitor” which allows you to create monitors for each individual service that is critical to you. But, what if you want to monitor every service on every system without manually creating monitors for each unique service name?

The solution

I worked this script up in a hurry one day, finding that it’s not always effective as there are many services set to run automatically on my system which are stopped purposely after they do their thing following a reboot of the system. However, I accommodated for this by adding an ignore section.

###Configuration #Put a comma separated list of the ones to ignore. #Example: "Service DisplayName 1","Service DisplayName 2" $ServicesToIgnore = "Avira Mail Protection","Google Update Service (gupdate)","Software Protection","Backblaze Service","Microsoft .NET Framework NGEN v4.0.30319_X86","Microsoft .NET Framework NGEN v4.0.30319_X64" ###End Configuration #Default to up $bDown = 0 #Get device information $ip = $Context.GetProperty("Address"); $DnsEntry = [System.Net.DNS]::GetHostByAddress($ip) $DnsName = [string]$DnsEntry.HostName; # Get the Windows credentials $WinUser = $Context.GetProperty("CredWindows:DomainAndUserid"); $WinPass = $Context.GetProperty("CredWindows:Password"); $pwd = ConvertTo-SecureString $WinPass -asplaintext -force $cred = new-object -typename System.Management.Automation.PSCredential -argumentlist $WinUser,$pwd $Query = "" $Query = "select * from win32_service where StartMode like '%Auto%' and State != 'Running'" ForEach($Service in $ServicesToIgnore){ $Query = $Query + " and DisplayName != '$Service'" } #Get all services that are set to 'Auto' and are not in 'Running' state $Services = (gwmi -ComputerName $DnsName -Credential $cred -Query $Query).DisplayName If($Services.Length -gt 0){ $bDown = 1 ForEach($service in $Services){ $sMsg += "`r `n$service" } } $Context.SetResult($bDown, $sMsg)


Leave a Comment


CAPTCHA Image
Reload Image

This site uses Akismet to reduce spam. Learn how your comment data is processed.