Shaun Cassells at MyITForum.com

SMS 2003 and ConfigMgr 2007, PowerShell, Scripting, Finance, Fitness and Fun

PowerShell: How do I connect to SMS 2003 and perform Client Actions?

The Microsoft.SMS.Client COM object exposes several client actions.

 

PS C:\ > $a = New-Object -comObject Microsoft.SMS.Client

 

Now what do I do with the $a variable?  Let’s see what members are exposed from the COM.

 

PS C:\> New-Object -comObject Microsoft.SMS.Client | get-member

 

Note: the following results are contained in the SMS 2003 SDK 3.1

  • AutoDiscoverSite
    • Retrieves the site code of the locally available site based on the client's current roaming situation, without assigning the client to the site
  • DiscoverDefaultMP
    • Retrieves the assigned management point for a client, without assigning the client to the management point.
  • EnableAutoAssignment
    • Enables or disables the auto-assignment feature of the client.
  • GetAssignedSite
    • Gets the currently assigned site of the client
  • GetCurrentManagementPoint
    • Gets the management point to which the client is currently assigned.
    • Note: This method is deprecated. Use the ISmsClient2::GetCurrentManagementPointEx Method
  • ReAssignSite
    • Forces the client to rediscover its assigned site and then reassign itself to that site.
  • RemoveAssignedSites
    • Removes all site assignments for the client
  • ResyncPolicy
  • SetAssignedSite
    • Sets the client's assigned site
  • SetCurrentManagementPoint
    • Sets the current management point for the client
  • UseAdminLocator
 
  • Local administrator privileges are required to call this interface.
    • The IID for ISmsClient is DF56E387-A8BF-409a-8D1C-33CD1908C01A
 

Cool, show me how to use one.

PS C:\ > $a.AutoDiscoverSite()

Returns the 3 char Site Code

 

Example: Change a site code, force a policy resynchronization, then set client back to default Site Code.

 

PS C:\ > $a = New-Object -comObject Microsoft.SMS.Client

  1. Check what site is currently assigned

PS C:\ > $a.GetAssignedSite()

  1. Change Site Setting to Something else

PS C:\> $a.SetAssignedSite("LAB")

  1. Check What site is currently assigned

PS C:\ > $a.GetAssignedSite()

  1. Force a policy refresh and send new discovery record

PS C:\> $a.ResyncPolicy()

  1. Force the client back to the correct Site Code

PS C:\> $a.ReAssignSite()

 

Step 2 would fail: if you do not have security rights to perform that action:

Exception calling "SetAssignedSite" with "1" argument(s): "Failed to set the assigned site."At line:1 char:19+ $a.SetAssignedSite( <<<< "LAB") 

Step 4 would fail: if you do not have security rights to perform that action:

Exception calling "ResyncPolicy" with "0" argument(s): "Failed to resync policy. One or more settings may be missing from WMI"At line:1 char:16+ $a.ResyncPolicy( <<<< )

 

Comments

No Comments