problem getting services from several machines

by fgc at 2012-12-20 14:29:37

I was trying to get all running services from a couple of computers in an AD environment. I was using the following Powershell command:

get-adcomputer -filter * | select @{label="Computername";expression={$.name}} | get-service -name *

To my surprise I’m getting the services of my local machine serveral times ( as much computers exist ), instead of getting the services of all the different computers.

If I’m using real names for the services, the script is running as expected, e.g.:

get-adcomputer -filter * | select @{label="Computername";expression={$
.name}} | get-service -name audiosrv

This time the property "Computername" from the pipe is correctly submitted to "get-service". I’m wondering, cause the help for "get-service" is showing, that the "*" can be used for the parameter ‘name’.

I’m not looking for another way to solve the problem - I would like to understand why the ‘pipelining by parameter name’ doesn’t work as expected.


by Klaas at 2012-12-21 00:27:12
I’m not 100% sure, but I believe the input to Get-Service will first be bound to the -Name parameter if there isn’t anything else assigned there. Probably the wildcard character doesn’t fill in the needs, while the "audiosrv" does. In that case the input will be used for the -computername parameter.
The ByValue method will be used first and ByPropertyName only when ByValue fails, and the -Name parameter has position 1.
Don explains this a lot better than I can in ‘Learn Powershell3 In a month of lunches’, ch 9, p 99.