簡體   English   中英

為什么不直接使用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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM