![](/img/trans.png)
[英]Command works directly in Powershell but doesn't work when executed through a linux system using powershell
[英]why doesn't splat work directly with command in powershell?
為什么以下工作:
Get-WmiObject -class Win32_OperatingSystem
這也有效:
$params = @{class='Win32_OperatingSystem'}
Get-WmiObject @params
但這不起作用:
Get-WmiObject @{class='Win32_OperatingSystem'}
錯誤:
Get-WmiObject : Invalid query "select * from System.Collections.Hashtable"
At line:1 char:1
+ Get-WmiObject @{class='Win32_OperatingSystem'}
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Get-WmiObject], ManagementException
+ FullyQualifiedErrorId : GetWMIManagementException,Microsoft.PowerShell.Commands.GetWmiObjectCommand
Splatting是一種將參數值集合作為單元傳遞給命令的方法。 Windows PowerShell將集合中的每個值與命令參數相關聯。 Splatted參數值存儲在命名的splatting變量中,這些變量看起來像標准變量,但以At符號(@)而不是美元符號($)開頭。 At符號告訴Windows PowerShell您傳遞的是值集合,而不是單個值。
如果不將它存儲到變量中,則它不是splatting,它是一個簡單的哈希表,它作為位置參數傳遞給命令。
參考
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.