# Sample: query explicitly selected local services without changing them. [CmdletBinding()] param([string[]]$Name = @('EventLog', 'Dnscache')) foreach ($serviceName in $Name) { try { $service = Get-Service -Name $serviceName -ErrorAction Stop [pscustomobject]@{ Service = $service.Name; Status = [string]$service.Status; Note = 'Observed state' } } catch { [pscustomobject]@{ Service = $serviceName; Status = 'Unknown'; Note = 'Unavailable or inaccessible' } } } # A stopped service is not automatically a fault: compare with its intended state.