
Shawn Samuels (Customer) asked a question.
Hi, I'm posting this as is. Maybe it'll help someone else out. We were looking for a way to monitor many window services at once, but not all services. Trying to set up one service monitor at a time was going to be prohibitive. We hit on using a powershell script and to monitor anything set to Automatic. We included an "ignore list" where we could add services that are not always running so they don't generate false positives. Took about two weeks to build out our list. YMMV. We used the Services' Display Name as the value to use in the ignore list but you could change that.
PowerShell Active Monitor
Name: Windows Services Monitor
Description: PowerShell monitor - This monitors Windows Server Services that are set to Automatic. If the service is set to Automatic and is not running an alert will be generated.
Timeout: 60 Seconds
Script Text:
- # WhatsUp Gold Active Script Monitor (PowerShell)
-
- # Windows Services: Automatic but Not Running (WMI)
-
- # Includes an ignore list by DisplayName (exact match)
-
-
-
- $rc = 0
-
- $msg = ""
-
-
-
- try {
-
- $addr = [string]$Context.GetProperty("Address")
-
- $user = [string]$Context.GetProperty("CredWindows:DomainAndUserid")
-
- $pass = [string]$Context.GetProperty("CredWindows:Password")
-
-
-
- if ([string]::IsNullOrEmpty($user) -or [string]::IsNullOrEmpty($pass)) {
-
- throw "Missing Windows credential (CredWindows) on this device."
-
- }
-
-
-
- $sec = ConvertTo-SecureString $pass -AsPlainText -Force
-
- $cred = New-Object System.Management.Automation.PSCredential($user, $sec)
-
-
-
- # Pull services that should be running (Automatic) but are not
-
- $svc = Get-WmiObject -Class Win32_Service -ComputerName $addr -Credential $cred -Filter "StartMode='Auto' AND State<>'Running'"
-
-
-
- # -----------------------------
-
- # IGNORE LIST (DisplayName)
-
- # -----------------------------
-
- $ignore = @(
-
- "Microsoft Edge Update Service (edgeupdate)",
-
- "AppX Deployment Service (AppXSVC)",
-
- "Background Intelligent Transfer Service",
-
- "Connected Devices Platform Service",
-
- "Downloaded Maps Manager",
-
- "Delivery Optimization",
-
- "Device Management Wireless Application Protocol (WAP) Push message Routing Service",
-
- "Google Updater Internal Service (GoogleUpdaterInternalService147.0.7703.0)",
-
- "Google Updater Service (GoogleUpdaterService147.0.7703.0)",
-
- "Google Updater Internal Service (GoogleUpdaterInternalService148.0.7730.0)",
-
- "Google Updater Service (GoogleUpdaterService148.0.7730.0)",
-
- "Group Policy Client",
-
- "MDM Integration Service",
-
- "Windows Biometric Service",
-
- "Remote Registry",
-
- "SharePoint Migration Service",
-
- "Software Protection",
-
- "SysMain",
-
- "Volume Shadow Copy",
-
- "wuauserv",
-
- "Windows Modules Installer",
-
- "Windows Time",
-
- "Windows Update"
-
- )
-
-
-
- # Remove ignored services
-
- $svc = $svc | Where-Object { $ignore -notcontains $_.DisplayName }
-
-
-
- # If anything remains, alert DOWN and list them
-
- if ($svc) {
-
- $rc = 1
-
- $lines = @()
-
- foreach ($s in $svc) {
-
- $lines += ($s.DisplayName + " [" + $s.Name + "] State=" + $s.State)
-
- }
-
- $msg = "Automatic services NOT running on " + $addr + ":`r`n" + ($lines -join "`r`n")
-
- }
-
- else {
-
- $msg = "OK - All Automatic services are running (after ignore list) on " + $addr + "."
-
- }
-
- }
-
- catch {
-
- $rc = 1
-
- $msg = "Script error: " + $_.Exception.Message
-
- }
-
-
-
- $Context.SetResult($rc, $msg)
@Shawn Samuels (Customer)
Thank you very much for sharing this - I'm sure someone will get use out of this.
Just so you are aware, it is possible to bulk create service monitors as part of the creation process - We have a multi selection for this exact scenario
I edited your post to use the script block function to make your code easier to read and copy.