PowerShell: Get-Service ComputerName parameter binding bug
Please refer to the following examples. The ComputerName parameter (ValueFromPipelineByPropertyName) in combination with the "Name" or "DisplayName" parameters does not always scan the correct computers with the Get-Service cmdlet. Just in the first case, all target comptuers are queried. In the other cases, the first object is queried multiple times.
$Objects = [PSCustomObject] @{ ComputerName = 'LON-DC1' }, [PSCustomObject] @{ ComputerName = 'LON-CL1' }
SUCCESS: Works as expected, gets the service for each machine
$Objects | Get-Service -Name Netlogon | Format-Table MachineName, ServiceName, Status -AutoSize
MachineName ServiceName Status
LON-DC1 Netlogon Running
LON-CL1 Netlogon Running
ERROR: Uses the first comptuer name all queries
$Objects | Get-Service -Name * | Format-Table MachineName, ServiceName, Status -AutoSize
MachineName ServiceName Status
LON-DC1 ADWS Running
LON-DC1 AeLookupSvc Stopped
[...]
LON-DC1 wuauserv Stopped
LON-DC1 wudfsvc Stopped
ERROR: Uses the first comptuer name all queries
$Objects | Get-Service -DisplayName Netlogon | Format-Table MachineName, ServiceName, Status -AutoSize
MachineName ServiceName Status
LON-DC1 Netlogon Running
LON-DC1 Netlogon Running
ERROR: Uses the first comptuer name all queries
$Objects | Get-Service -DisplayName * | Format-Table MachineName, ServiceName, Status -AutoSize
MachineName ServiceName Status
LON-DC1 ADWS Running
LON-DC1 AeLookupSvc Stopped
[...]
LON-DC1 wuauserv Stopped
LON-DC1 wudfsvc Stopped

2 comments
-
Sebastian commented
Could reproduce the same issue.
Powershell Version
Version 5.1.14393.0 -
Sebastian N. commented
I can confirm this.
PS C:\WINDOWS\system32> (systeminfo.exe | select -First 2 -Skip 2) -replace ".+:\s+",""
Microsoft Windows 10 Pro
10.0.10586 Build 10586on
PS C:\WINDOWS\system32> $PSVersionTable
Name Value
---- -----
CLRVersion 2.0.50727.8670
BuildVersion 6.1.7600.16385
PSVersion 2.0
WSManStackVersion 2.0
PSCompatibleVersions {1.0, 2.0}
SerializationVersion 1.1.0.1
PSRemotingProtocolVersion 2.1and
PS C:\WINDOWS\system32> $PSVersionTable
Name Value
---- -----
PSVersion 5.0.10586.63
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.10586.63
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1