Remotely run WMIClass command against multiple computerts

jellekamma 221 Reputation points
2021-02-22T08:48:34.483+00:00

Hi,

I am using this command to force sccm updates on remote computers: ([wmiclass]'ROOT\ccm\ClientSDK:CCM_SoftwareUpdatesManager').InstallUpdates([System.Management.ManagementObject[]] (get-wmiobject -query 'SELECT * FROM CCM_SoftwareUpdate' -namespace 'ROOT\ccm\ClientSDK'))

Currently I enter-pssession, run the command and exit the session and start a new session. This is a pretty hassle.
How do I remotely run the command to a list of servers?

Thanks!

Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,363 questions
0 comments No comments
{count} votes

Accepted answer
  1. Bill Stewart 181 Reputation points
    2021-02-22T16:39:03.847+00:00

    The "looping" version of that with computer name strings would look something like this:

    foreach ( $computerName in $computerNames ) {
      ([WMIClass] "\\$computerName\root\CCM\ClientSDK:CCM_SoftwareUpdatesManager").InstallUpdates([Management.ManagementObject[]])
      Get-WmiObject -ComputerName $computerName -Query "SELECT * FROM CCM_SoftwareUpdate" -Namespace "root\ccm\ClientSDK"
    }
    

    This presumes that the variable $computerNames has a list of computer names, one per line, and that the host-based firewall on each machine you want to connect to will allow the connection.

    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. jellekamma 221 Reputation points
    2021-02-23T12:15:23.48+00:00

    thanks Bill! I will give it a try