And yet another option:
[pre] function Get-MrService { [CmdletBinding()] param ( [ValidateNotNullOrEmpty()] [string[]]$ComputerName = ('s1','s2','s3'), [ValidateNotNullOrEmpty()] [string[]]$ServiceName = 'bits' ) foreach ($Computer in $ComputerName) { foreach ($Service in $ServiceName) { $ServiceInfo = Get-Service -Name $Service -ComputerName $Computer -ErrorAction SilentlyContinue if (-not($ServiceInfo)) { $ServiceInfo = @{ MachineName = $Computer Name = $Service Status = 'Unreachable' } } [PSCustomObject]@{ ComputerName = $ServiceInfo.MachineName Name = $ServiceInfo.Name Status = $ServiceInfo.Status } } } }
[/pre]