Scenario 4 – checking for SCCM services
Another common scenario when performing Configuration Manager health checks is to check for the existence of SCCM services, including the startup type and the status. We can create a function that receives the server name, service name, expected status, and expected startup type as parameters. It is recommended that you make changing variables parameters of the function so that we can make the function universal:
Function Get-ServiceStatus($ServerList, [string]$Servicename, [string]$Status, [string]$Startup) { foreach ($Comp in $ServerList) { if($Temp = Get-WmiObject Win32_Service -ComputerName $Comp | where {$_.Name -eq $Servicename } | select Name, StartMode, State, Displayname) { $Sname = $Temp.Displayname $ServiceState = $Temp.State $ServiceMode = $Temp.StartMode if(($ServiceState -eq $Status) -and ($ServiceMode -eq $Startup)) { Write-Host "service $Sname on $comp is Healthy" –foregroundcolor...