获取 CIMInstance |无法在拼接参数中包含"-Query"参数



我有一个提取一些CIM信息的脚本,直接从终端(在本地机器上,而不是远程CIM会话)运行命令是成功的:

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

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

如果我尝试像下面这样分割参数:

$curParams = @{
Namespace = "rootsmssite_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 FilesWindowsPowerShellModulesABC-MECMABC-MECM.psm1:321 char:21
+     Get-CimInstance @curParams
+                     ~~~~~~~~~~
+ CategoryInfo          : WriteError: (:) [Get-CimInstance], ParameterBindingException
+ FullyQualifiedErrorId : ParameterBindingFailed,Microsoft.Management.Infrastructure.CimCmdlets.GetCimInstanceCommand

通过一些简短的测试,它看起来像'Query'参数在使用飞溅参数时不知怎么不存在?

在文档中:

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

有多个"语法"选项,其中只有一些包含"查询"参数。

谁能帮助解释为什么这个错误发生,在什么情况下查询不被接受?

编辑:

当然,我(至少部分)在发帖后立即解决了这个问题。

由于某些原因,在溅射时包含'classname'参数导致查询失败。

删除该参数解决了问题。

看起来只是不一致的行为,因为具有所有参数的完全相同的命令从终端完成,而没有溅射。

也许有人可以解释为什么在执行带有命名参数或飞溅的命令时这种行为是不同的?

由于某些原因,在溅射时包含'classname'参数导致查询失败。

删除该参数解决了问题。

看起来只是不一致的行为,因为具有所有参数的完全相同的命令从终端完成,而没有溅射。

最新更新