WMI / Powershell and the Configuration Manager Client
A bit about me first :- my name is Anthony Watherston and I’m a Premier Field Engineer in Melbourne. Currently working with Configuration Manager and Orchestrator – plus I try to do everything I can with Powershell!
Last week I had a need for accessing the Configuration Manager client on a remote system. As this was developing an automated solution I didn’t have the option to use the Control Panel applet or the Configuration Manager console to trigger actions on the client. What I needed to find was a way to trigger actions remotely using Powershell – the answer lies in the methods associated with WMI classes.
As WMI is a class based system, each object has associated properties and many of these have methods as well. Below are some examples of how to call some of the built in WMI methods which are part of the Configuration Manager Client namespace. A detailed description of the client and its classes can be found at https://msdn.microsoft.com/en-us/library/jj874139.aspx
Determine if a system has a reboot pending
The Configuration Manager client has a class called CCM_ClientUtilities – in Wbemtest I can access it by connecting to root\ccm\clientsdk. In the diagram below we can see the methods associated with this class.
So how do I trigger these methods using Powershell – the Invoke-WMIMethod cmdlet.
To get a list of associated methods I can use the command below: -
Get-WmiObject -Namespace root\ccm\clientsdk -Class CCM_ClientUtilities -List | select -ExpandProperty Methods
This gives me the list of methods below:-
Now if I want to trigger one of these methods I can use my Invoke-WMIMethod cmdlet and supply the method name.
Invoke-WmiMethod -Namespace root\ccm\clientsdk -Class CCM_ClientUtilities -Name DetermineIfRebootPending
There is a lot of information in these results, I only want to know the value of the RebootPending flag. I can wrap my command in parentheses and specify the property name after a dot to only return that value.
(Invoke-WmiMethod -ComputerName $remoteMachine -Namespace root\ccm\clientsdk -Class CCM_ClientUtilities -Name DetermineIfRebootPending).RebootPending
Now that I have this information I could force the machine to reboot if the result is true using one of the other methods in this class – RestartComputer.
$rebootPending = (Invoke-WmiMethod -Namespace root\ccm\clientsdk -Class CCM_ClientUtilities -Name DetermineIfRebootPending).RebootPending
if ($rebootPending)
{
Invoke-WmiMethod -Namespace root\ccm\clientsdk -Class CCM_ClientUtilities -Name RestartComputer
}
Of course if I wanted to perform this on a remote machine I can use the WMIObject computername parameter and specify a remote machine.
$remoteMachine = "AW-SVR01"
$rebootPending = (Invoke-WmiMethod -ComputerName $remoteMachine -Namespace root\ccm\clientsdk -Class CCM_ClientUtilities -Name DetermineIfRebootPending).RebootPending
if ($rebootPending)
{
Invoke-WmiMethod -ComputerName $remoteMachine -Namespace root\ccm\clientsdk -Class CCM_ClientUtilities -Name RestartComputer
}
Trigger a client action
I can use the same theory in order to trigger policy retrieval on a machine. Each action is specified by a schedule value, supplying these to the TriggerSchedule method will force the client to perform an action. For instance the script below will trigger a Machine Policy Retrieval & Evaluation cycle on a client.
$trigger = "{00000000-0000-0000-0000-000000000021}"
Invoke-WmiMethod -Namespace root\ccm -Class sms_client -Name TriggerSchedule $trigger
As with the other script I can supply a computer name parameter to the command to have it execute on a remote machine.
Determine assigned site
The last method is one which will allow you to determine a client’s assigned site. I can use the GetAssignedSite method to retrieve the site code.
(Invoke-WMIMethod –Namespace root\ccm –Class SMS_Client –Name GetAssignedSiteCode).sSiteCode
There are many more methods available to use within WMI – stay tuned for more.
Comments
- Anonymous
September 04, 2014
Nice tip - Anonymous
September 06, 2014
Thanks for the post mate, now I know the easy way to check reboot pending! - Anonymous
October 27, 2014
Perfect, I really appreciate these posts! - Anonymous
May 22, 2015
How could I change the method "DetermineIfRebootPending" to True for testing purposes? - Anonymous
May 22, 2015
can't seem to get Invoke-WmiMethod to work!
Invoke-WMIMethod : This method is not implemented in any class - Anonymous
May 22, 2015
The comment has been removed - Anonymous
May 31, 2015
@Heyvoon The only way I know of to get this to turn True is to install something that requires a reboot - e.g. a Security Update. - Anonymous
February 10, 2016
Great post! Is it possible to find out what SCCM collections the current client is part of (from the client itself and not server/db) using wmi?- Anonymous
February 14, 2016
Not possible - the client doesn't know what collections it is a part of. Only the site server will know this.
- Anonymous
- Anonymous
March 07, 2016
The comment has been removed - Anonymous
December 21, 2016
Hi Anthony,With WMI can we determine what active advertisements/deployments are available on the client ?and followed by triggering the installation of a specific deployment [identifying with a Deployment ID]