This was done for testing and we have the solution but I would like to dig deeper. I have a file list.txt that contains names of computers:
name
computer1
computer2
computer3
...
when I try
Import-Csv .\list.txt | Select-Object -property @{n="computername";e={$_.name}} | Get-Service
we get an error "Get-Service : Cannot find any service with service name '@{computername=computer1}'." Which I understand as Get-Service trying to map computername=computer1 to the parameter "name" (name="computername=computer1") even though the parameter "computername" is specified.
My solution was to add the "name" parameter and it works as expected
Import-Csv .\list.txt | Select-Object -property @{n="computername";e={$_.name}} | Get-Service -name *
My question is, why? Get-Service should accept pipeline input byPropertyName and it recognizes computername. Why doesn't it bind it unless I specify another parameter? Neither "name", nor "computername" is required. Also
Get-Service
and
Get-Service -computername "computer1"
both work without specifying "name".