簡體   English   中英

獲取 CIMInstance | 無法在 splatted 參數中包含“-Query”參數

[英]Get-CIMInstance | Unable to include "-Query" parameter in splatted parameters

我有一個腳本提取一些 CIM 信息,直接從終端運行命令(在本地機器上,而不是遠程 CIM 會話上)是成功的:

Get-CimInstance -Namespace root\sms\site_SITECODE -Query "SELECT SMS_Collection.* FROM SMS_FullCollectionMembership, SMS_Collection where Name = '$($hostName)' and SMS_FullCollectionMembership.CollectionID = SMS_Collection.CollectionID"

返回正確的信息,一切正常。

如果我嘗試噴出如下參數:

$curParams = @{
    Namespace = "root\sms\site_SITECODE"
    ClassName = "SMS_FullCollectionMembership"
    Query     = "SELECT SMS_Collection.* FROM SMS_FullCollectionMembership, SMS_Collection where Name = '$($hostname)' and SMS_FullCollectionMembership.CollectionID = SMS_Collection.CollectionID"

}

Get-CimInstance @curParams

該命令失敗並出現以下錯誤:

Get-CimInstance : Cannot bind parameter 'Query' to the target. Exception setting "Query": "Unable to resolve the parameter set name."
At C:\Program Files\WindowsPowerShell\Modules\ABC-MECM\ABC-MECM.psm1:321 char:21
+     Get-CimInstance @curParams
+                     ~~~~~~~~~~
    + CategoryInfo          : WriteError: (:) [Get-CimInstance], ParameterBindingException
    + FullyQualifiedErrorId : ParameterBindingFailed,Microsoft.Management.Infrastructure.CimCmdlets.GetCimInstanceCommand

通過一些簡短的測試,使用 splatted 參數時,“查詢”參數似乎不存在?

在此處的文檔中:

https://docs.microsoft.com/en-us/powershell/module/cimcmdlets/get-ciminstance?view=powershell-7.2

有多個“語法”選項,其中只有一些包含“查詢”參數。

誰能幫助解釋為什么會發生此錯誤以及在什么情況下不接受查詢?

編輯:

當然,我(至少部分)在發布后立即解決了這個問題。

出於某種原因,在 splatting 時包含 'classname' 參數會導致查詢失敗。

刪除該參數解決了該問題。

看起來只是不一致的行為,因為具有所有參數的完全相同的命令從終端完成而沒有飛濺。

也許有人可以解釋為什么在執行帶有命名參數或飛濺的命令時這種行為會有所不同?

出於某種原因,在 splatting 時包含 'classname' 參數會導致查詢失敗。

刪除該參數解決了該問題。

看起來只是不一致的行為,因為具有所有參數的完全相同的命令從終端完成而沒有飛濺。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

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