本文介绍了将 WMI 调用转换为 CIM 调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写的代码假设使用 CIM 启动当前可用于服务器的任何补丁.由于我的网络需要 DCOM 协议,我必须使用 CIM.

The code I am writing is suppose to kick off any patches currently available to a server using CIM. And I have to use CIM due to the required DCOM protocol for my network.

我使用 ` 以便于查看

I'm using ` for easier viewing

以下 wmi 代码有效:

The following wmi code works:

$ComputerName = 'Foo'
[System.Management.ManagementObject[]] $CMMissingUpdates = @(`
    Get-WmiObject -ComputerName $ComputerName `
                  -Query "SELECT * FROM CCM_SoftwareUpdate WHERE ComplianceState = '0'" `
                  -Namespace "ROOT\ccm\ClientSDK" `
                  -ErrorAction Stop)
$null = (Get-WmiObject -ComputerName $ComputerName `
                       -Namespace "root\ccm\ClientSDK" `
                       -Class "CCM_SoftwareUpdatesManager" `
                       -List).InstallUpdates($CMMissingUpdates)

我使用 CIM 制作的东西不起作用:

What I've made using CIM that doesn't work:

$null = (Invoke-CimMethod -CimSession $Computer.CimSession `
                          -Namespace 'ROOT\ccm\ClientSDK' `
                          -ClassName 'CCM_SoftwareUpdatesManager' `
                          -MethodName 'InstallUpdates').InstallUpdates($CMMissingUpdates)

我不仅对 Invoke-CimMethod 的解决方案感兴趣,而且对它是如何解决的感兴趣.我似乎无法确定如何在 CIM 中查看和实现类的方法.

Not only am I interested in a solution to my Invoke-CimMethod but how it was solved. I can't seem to determine how to view and implement the methods of classes in CIM.

推荐答案

事实证明这是一个铸造问题.解决方案链接:https://www.reddit.com/r/PowerShell/comments/8zvsd8/kick_off_a_sccm_clients_install_all_available/

Turns out it was a casting issue. Link to solution: https://www.reddit.com/r/PowerShell/comments/8zvsd8/kick_off_a_sccm_clients_install_all_available/

最终解决方案:

$CMMissingUpdates = @( `
  Get-CimInstance -Query "SELECT * FROM CCM_SoftwareUpdate WHERE ComplianceState = '0'" `
                  -Namespace "ROOT\ccm\ClientSDK"
)
Invoke-CimMethod -Namespace 'ROOT\ccm\ClientSDK' `
                 -ClassName 'CCM_SoftwareUpdatesManager' `
                 -MethodName 'InstallUpdates' `
                 -Arguments @{
                    CCMUpdates = [cminstance[]]$CMMissingUpdates
                 }

这篇关于将 WMI 调用转换为 CIM 调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-06 18:07