Invoke-WMIMethod转换为Invoke-CimMethod,并将ciminstance作为Argument错误。

问题描述 投票:0回答:1

因此,试图在SCCM中用Invoke-CimMethod而不是Invoke-WMIMethod触发软件更新。

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
powershell wmi sccm
1个回答
1
投票

放了一天就想明白了。找到了一些帖子,引导我走向正确的方向。

最后的最后。

$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}

返回,更新安装。

ReturnValue PSComputerName
----------- --------------
          0
© www.soinside.com 2019 - 2024. All rights reserved.