Invoke-WMIMethod 转换为 Invoke-CimMethod with ciminstance 作为参数错误
Invoke-WMIMethod convert to Invoke-CimMethod with ciminstance as Argument error
因此,尝试使用 Invoke-CimMethod 而不是 Invoke-WMIMethod 在 SCCM 中触发软件更新。
WMIMethod 有效:
$UpdateID = 'Site_1EED8E47-D4D8-4823-883C-4FFE753FA233/SUM_0af47e05-17cb-4756-8610-09ce486df1ba'
$FeatureUpdate = Get-WmiObject -Namespace Root\CCM\ClientSDK -Class CCM_SoftwareUpdate -Filter "UpdateID like '$UpdateID'"
Invoke-WmiMethod -Namespace Root\ccm\clientSDK -Class CCM_SoftwareUpdatesManager -Name InstallUpdates -ArgumentList $FeatureUpdate
请注意 $FeatureUpdate 是一个更新实例:
$FeatureUpdate.GetType()
IsPublic IsSerial Name BaseType
-------- -------- ---- --------
True True ManagementObject System.Management.ManagementBaseObject
现在使用 Invoke-CimMethod:
$Instance=Get-CimInstance -Namespace Root\CCM\ClientSDK -Class CCM_SoftwareUpdate -Filter "UpdateID like '$UpdateID'"
Invoke-CimMethod -Namespace Root\ccm\clientSDK -Class CCM_SoftwareUpdatesManager -MethodeName InstallUpdates -Arguments @{CCMUpdates = $Instance}
Invoke-CimMethod : Type mismatch for parameter "CCMUpdates"
At line:1 char:1
+ Invoke-CimMethod -ClassName CCM_SoftwareUpdatesManager -Namespace Roo ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidType: (Root\CCM\Client...eUpdatesManager:String) [Invoke-CimMethod], CimException
+ FullyQualifiedErrorId : HRESULT 0x80041005,Microsoft.Management.Infrastructure.CimCmdlets.InvokeCimMethodCommand
注意实例:
$instance.GetType()
IsPublic IsSerial Name BaseType
-------- -------- ---- --------
True True CimInstance System.Object
在使用参数触发安装时我是否遗漏了什么?不确定这是否有帮助..
(((Get-CimClass -Namespace ROOT\ccm\ClientSDK -Class CCM_SoftwareUpdatesManager).CimClassMethods)|where {$_.name
-like 'InstallUpdates'}).parameters
Name CimType Qualifiers ReferenceClassName
---- ------- ---------- ------------------
CCMUpdates InstanceArray {EmbeddedInstance, ID, in}
(((Get-CimClass -Namespace ROOT\ccm\ClientSDK -Class CCM_SoftwareUpdatesManager).CimClassMethods)|where {$_.name
-like 'InstallUpdates'}).parameters.Qualifiers
Name Value CimType Flags
---- ----- ------- -----
EmbeddedInstance CCM_SoftwareUpdate String EnableOverride, ToSubclass
ID 0 SInt32 DisableOverride, ToSubclass
in True Boolean DisableOverride, ToSubclass
让它静置一天后想通了。找到了一些帖子,引导我朝着正确的方向前进。
最终决赛:
$UpdateID = 'Site_1EED8E47-D4D8-4823-883C-4FFE753FA233/SUM_0af47e05-17cb-4756-8610-09ce486df1ba'
$Instance = @(Get-CimInstance -Namespace ROOT\ccm\ClientSDK -ClassName CCM_SoftwareUpdate -Filter "UpdateID like '$UpdateID'")
Invoke-CimMethod -Namespace ROOT\ccm\ClientSDK -ClassName CCM_SoftwareUpdatesManager -MethodName InstallUpdates -Arguments @{CCMUpdates = [ciminstance[]]$Instance}
Returns,并更新安装:
ReturnValue PSComputerName
----------- --------------
0
因此,尝试使用 Invoke-CimMethod 而不是 Invoke-WMIMethod 在 SCCM 中触发软件更新。
WMIMethod 有效:
$UpdateID = 'Site_1EED8E47-D4D8-4823-883C-4FFE753FA233/SUM_0af47e05-17cb-4756-8610-09ce486df1ba'
$FeatureUpdate = Get-WmiObject -Namespace Root\CCM\ClientSDK -Class CCM_SoftwareUpdate -Filter "UpdateID like '$UpdateID'"
Invoke-WmiMethod -Namespace Root\ccm\clientSDK -Class CCM_SoftwareUpdatesManager -Name InstallUpdates -ArgumentList $FeatureUpdate
请注意 $FeatureUpdate 是一个更新实例:
$FeatureUpdate.GetType()
IsPublic IsSerial Name BaseType
-------- -------- ---- --------
True True ManagementObject System.Management.ManagementBaseObject
现在使用 Invoke-CimMethod:
$Instance=Get-CimInstance -Namespace Root\CCM\ClientSDK -Class CCM_SoftwareUpdate -Filter "UpdateID like '$UpdateID'"
Invoke-CimMethod -Namespace Root\ccm\clientSDK -Class CCM_SoftwareUpdatesManager -MethodeName InstallUpdates -Arguments @{CCMUpdates = $Instance}
Invoke-CimMethod : Type mismatch for parameter "CCMUpdates"
At line:1 char:1
+ Invoke-CimMethod -ClassName CCM_SoftwareUpdatesManager -Namespace Roo ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidType: (Root\CCM\Client...eUpdatesManager:String) [Invoke-CimMethod], CimException
+ FullyQualifiedErrorId : HRESULT 0x80041005,Microsoft.Management.Infrastructure.CimCmdlets.InvokeCimMethodCommand
注意实例:
$instance.GetType()
IsPublic IsSerial Name BaseType
-------- -------- ---- --------
True True CimInstance System.Object
在使用参数触发安装时我是否遗漏了什么?不确定这是否有帮助..
(((Get-CimClass -Namespace ROOT\ccm\ClientSDK -Class CCM_SoftwareUpdatesManager).CimClassMethods)|where {$_.name
-like 'InstallUpdates'}).parameters
Name CimType Qualifiers ReferenceClassName
---- ------- ---------- ------------------
CCMUpdates InstanceArray {EmbeddedInstance, ID, in}
(((Get-CimClass -Namespace ROOT\ccm\ClientSDK -Class CCM_SoftwareUpdatesManager).CimClassMethods)|where {$_.name
-like 'InstallUpdates'}).parameters.Qualifiers
Name Value CimType Flags
---- ----- ------- -----
EmbeddedInstance CCM_SoftwareUpdate String EnableOverride, ToSubclass
ID 0 SInt32 DisableOverride, ToSubclass
in True Boolean DisableOverride, ToSubclass
让它静置一天后想通了。找到了一些帖子,引导我朝着正确的方向前进。
最终决赛:
$UpdateID = 'Site_1EED8E47-D4D8-4823-883C-4FFE753FA233/SUM_0af47e05-17cb-4756-8610-09ce486df1ba'
$Instance = @(Get-CimInstance -Namespace ROOT\ccm\ClientSDK -ClassName CCM_SoftwareUpdate -Filter "UpdateID like '$UpdateID'")
Invoke-CimMethod -Namespace ROOT\ccm\ClientSDK -ClassName CCM_SoftwareUpdatesManager -MethodName InstallUpdates -Arguments @{CCMUpdates = [ciminstance[]]$Instance}
Returns,并更新安装:
ReturnValue PSComputerName
----------- --------------
0