PowerShell & SCCM – Client

In the previous posts we created a new Package containing Windows PowerShell and distributed it to all all XP clients in the “All Windows XP Systems” Collection. Assuming that everything went OK the package should have been distributed and installed on the Client.

With Windows PowerShell installed on the Client we can manage the SMS Client using Windows PowerShell. In the Install.bat file used when installing the program we also enabled PowerShell remoting so we can run commands against the client remote. Here’s an example on how to connect to the Client remote.

PS > Enter-PSSession XP01.powershell.nu
[xp01.powershell.nu]: PS >

We can connect to the SMS Client using the Microsoft.SMS.Client COM Object as shown below.

PS > $smsClient = New-Object -ComObject Microsoft.SMS.Client

The COM Object supports a couple of methods that we can use to manage the SMS Client. We can display the properties by sending the object through a pipeline to the Get-Member cmdlet.

PS > $smsClient | Get-Member

   TypeName: System.__ComObject#{d535c884-6b82-47dd-9a15-

Name                           MemberType Definition
----                           ---------- ----------
AutoDiscoverSite               Method     string AutoDisc
ClearProxy                     Method     void ClearProxy
DiscoverDefaultMP              Method     string Discover
EnableAutoAssignment           Method     void EnableAuto
GetAssignedSite                Method     string GetAssig
GetCurrentManagementPoint      Method     string GetCurre
GetCurrentManagementPointEx    Method     void GetCurrent
GetDnsSuffix                   Method     string GetDnsSu
GetInternetManagementPointFQDN Method     string GetInter
GetProxy                       Method     void GetProxy (
IsClientAlwaysOnInternet       Method     int IsClientAlw
IsClientOnInternet             Method     int IsClientOnI
MSIReinstallClient             Method     uint MSIReinsta
ReAssignSite                   Method     string ReAssign
RemoveAssignedSites            Method     void RemoveAssi
ResyncPolicy                   Method     void ResyncPoli
SendClientAssignmentMessage    Method     void SendClient
SetAssignedSite                Method     void SetAssigne
SetClientProvisioningMode      Method     void SetClientP
SetCurrentManagementPoint      Method     void SetCurrent
SetDnsSuffix                   Method     void SetDnsSuff
SetInternetManagementPointFQDN Method     void SetInterne
SetProxy                       Method     void SetProxy (
UseAdminLocator                Method     void UseAdminLo

If we want to display the Assigned Site we use the GetAssignedSite() method.

PS > $smsClient.GetAssignedSite()

It’s also possible to change the Assigned Site using the SetAssignedSite() method. In the example below we change site from LAB to P01.

PS > $smsClient.SetAssignedSite("P01")
PS > $smsClient.GetAssignedSite()

We can even set the Current SMS Advanced Client Management Point using the SetCurrentManagementPoint() method. The method accepts an IP-Address followed by [int]1 or a Computer Name followed by [int]0.

PS > $smsClient.SetCurrentManagementPoint("SCCM",0)

It’s also possible to use the CPAppletMgr, which is a COM automation class that provides an automated way to perform the same tasks as the Configuration Manager program on the Client.

First we store the COM Object in a variable.

PS > $cpAppletMgr = New-Object -ComObject CPApplet.CPAppletMgr

We can display the supported methods using the Get-Member cmdlet as shown below.

PS > $cpAppletMgr | Get-Member

   TypeName: System.__ComObject#{279463bb-1034-4fb5-878e-4a330a08beab}

Name                MemberType Definition
----                ---------- ----------
GetClientActions    Method     IClientActions GetClientActions ()
GetClientComponents Method     IClientComponents GetClientComponents ()
GetClientProperties Method     IClientProperties GetClientProperties ()

Let’s take a look at the GetClientActions() method. If we simply use the method the available we get a list of the Client Actions available.

PS > $cpAppletMgr.GetClientActions()

ActionID                      Name                           DisplayNameResID DisplayNameResDLL
--------                      ----                           ---------------- -----------------
{00000000-0000-0000-0000-0... Software Inventory Collect...             10005 cfg_res.dll
{00000000-0000-0000-0000-0... MSI Product Source Update ...             10010 cfg_res.dll
{00000000-0000-0000-0000-0... Hardware Inventory Collect...             10001 cfg_res.dll
{00000000-0000-0000-0000-0... Software Updates Assignmen...             10011 cfg_res.dll
{00000000-0000-0000-0000-0... Standard File Collection C...             10006 cfg_res.dll
{00000000-0000-0000-0000-0... Updates Source Scan Cycle                 10013 cfg_res.dll
{00000000-0000-0000-0000-0... Discovery Data Collection ...             10004 cfg_res.dll
{3A88A2F3-0C39-45fa-8959-8... Request & Evaluate User Po...             10007 cfg_res.dll
{00000000-0000-0000-0000-0... Peer DP Maintenance Task                  10012 cfg_res.dll
{8EF4D77C-8A23-45c8-BEC3-6... Request & Evaluate Machine...             10008 cfg_res.dll
{00000000-0000-0000-0000-0... Software Metering Usage Re...             10009 cfg_res.dll

We can retrieve a specific Action using the Where-Object cmdlet. In the example below we retrieve the “Request & Evaluate Machine Policy” Action.

PS > $machinePolicy = $cpAppletMgr.GetClientActions() | 
>> Where-Object { $_.Name -eq "Request & Evaluate Machine Policy" }

Now that we’ve stored a specific Action in a variable we can simply use the PerformAction() method to perform the Action.

PS > $machinePolicy.PerformAction()

Pretty Cool!

Rating 4.33 out of 5

3 thoughts on “PowerShell & SCCM – Client

  1. Pingback: PowerShell.nu » PowerShell & SCCM – Advertisement

  2. This is the best SCCM / PowerShell Tutorial I have come across. it has opened my eyes and horizon on what to do. Keep up the good work man!!!!!

  3. Anyone come across a way to get this information on remote PCs without using PS-Session or PS-Invoke?

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Anti-Spam Protection by WP-SpamFree