【发布时间】:2018-05-13 18:13:45
【问题描述】:
看起来像一个错误,不是吗?在这种情况下,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
【问题讨论】:
-
-ComputerName 参数已从 PS 6.x 中的 Get-Service 中删除,但在较低版本中似乎是一个错误
标签: powershell pipe pipeline parameterbinding