看起来像一个错误,不是吗?在这种情况下,PowerShell 将哈希表转换为字符串“@{computername=comp001}”并尝试将其与 -Name (ByValue) 而不是 -ComputerName (ByPropertyName) 一起使用。即使是 PS 6 也能做到。管道Get-Service -Name *
工作正常。
PS C:\> [pscustomobject]@{computername='comp001'} | get-service
get-service : Cannot find any service with service name '@{computername=comp001}'.
At line:1 char:45
+ [pscustomobject]@{computername='comp001'} | get-service
+ ~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (@{computername=comp001}:String)
[Get-Service], ServiceCommandException
+ FullyQualifiedErrorId :
NoServiceFoundForGivenName,Microsoft.PowerShell.Commands.GetServiceCommand