Forum Discussion
Adamzter81
Jul 31, 2024Copper Contributor
Powershell to Monitor Services
Hello, I have specific services that I would like to monitor on specific servers and send out alert if service is stopped. Below is a script that works for monitoring one service on a specific s...
- Aug 01, 2024
#Loop through all servers and services for each server
foreach ($servername in $servernames)
foreach ($ServiceName in $ServiceNames) {
If (Get-Service -ComputerName "$servername" -Name "$ServiceName") {
$ServiceStatus = Get-Service -ComputerName "$servername" -Name "$ServiceName"
$ServiceState = $ServiceStatus.Status
ServiceCheck
}
}
}
This checks if service is there, then checks status
Adamzter81
Aug 01, 2024Copper Contributor
Thanks Harm. The problem is not all services are running on all servers. For example ADDS service may not be running on an App server so if we go with above solution, it will generate false alerts maybe, I will still test it out.
Aug 24, 2024
Did that work for you?