Working with SMS Site Settings

Working with SMS site settings in a script can be useful to:

  • Change a site setting in a large number of sites without human intervention.

  • Report on site settings (to confirm all sites are set up correctly).

SMS is controlled through site control files. Site control files are represented in WMI by using the SMS_SiteControlFile class. SMS_SiteControlFile has methods to enable scripts to manipulate site control files. The methods allow your scripts to retrieve a current copy of a site control file and to later commit any changes.

Important

  • For security reasons, SMS account passwords cannot be set in scripts. You can, however, script SMS Administrator console operations to simulate an administrator setting the passwords. For more information, see the "Scripting Console Operations" section later in this appendix.
On This Page

How to Work with SMS Site Settings

How to Work with SMS Site Settings

Working with SMS site settings in scripts involves the following steps:

  1. Create a session handle to use with site control files.

  2. Get a site control file for the site that you want to manage. Site control files are available for the site to which your script connects and for all sites that report to that site. You must also specify whether you want to use file type 2 (proposed settings - to change settings) or type 1 (actual settings - to report on settings). You can directly change file type 1; however, if you change file type 1, the change will not get processed by Hierarchy Manager and Site Component Manager, and thus will not have any effect.

  3. Get a class based on the SMS_SiteControlItem class that represents the relevant part of the site control file that you need. If a new item is being created, such as an address, this involves launching an instance of the class. Usually, your script gets a specific instance of the class. For more information about the available SMS_SiteControlItem classes, see the Microsoft Systems Management Server 2003 Software Development Kit. Also, read a sample site control file to find the details that you plan to change, and then determine the class based on the group that the details are stored in.

  4. Change the values.

  5. Save the changes.

  6. Commit the site control file changes.

  7. Release the session handle.

Steps 1, 2, 5, 6, and 7 do not change much, if at all, from script to script. Therefore, you can copy them from any sample script that works with SMS site settings.

Step 3 varies in limited ways. If you cannot find an sample script that is similar to what you need, you might be able to piece the details together with some experimentation. What is important is that you select the correct SMS_SiteControlItem class and that you specify valid values for the key properties that are used to retrieve an instance of the class.

As with other scripts, it might be useful to look at the available instances of the class. Browsing instances can be done with CIM Studio or similar tools, but for SMS_SiteControlItem classes you cannot simply use the Instances button. Instead, you must execute a query, by using the WQL Queries button, such as shown in the following:

Select * FROM SMS_SCI_ClientComp WHERE SiteCode="B2K" AND FileType=1

Sample C.24 is a typical script for working with SMS site settings, except that the details for step 4 are not illustrated. For examples of step 4, see the other samples in this appendix.

Sample C.24 SiteSettings.vbs - a commented template of a typical site setting script

strSiteCode="MSO" Set lLocator = CreateObject("WbemScripting.SWbemLocator")
 Set wbemservices = lLocator.ConnectServer( , "root\sms\site_" & strSiteCode)
 'step 1: set WbemContext=CreateObject("WbemScripting.SWbemNamedValueSet") WbemContext.Add
 "SessionHandle",WbemServices.ExecMethod("SMS_SiteControlFile","GetSessionHandle").SessionHandle
 'step 2: WbemServices.ExecMethod "SMS_SiteControlFile.Filetype=2,
 Sitecode=""" & strSiteCode & """", "Refresh", , , WbemContext
 'step 3 (details will vary, and sometimes an instance will be spawned, rather 'than retrieved):
 Set WbemInst = WbemServices.Get("SMS_SCI_ClientComp.Filetype=1,
 Itemtype=""Client Component"",Sitecode=""" & Sitecode & """,ItemName=""Remote Control""", , WbemContext)
 'step 4 varies widely
 'step 5: WbemInst.Put_ , WbemContext
 'step 6: WbemServices.ExecMethod "SMS_SiteControlFile.Filetype=1,
 Sitecode=""" & strSitecode & """", "Commit", , , WbemContext
 'step 7: WbemServices.Get("SMS_SiteControlFile").ReleaseSessionHandle WbemContext.Item("SessionHandle").Value

Step 4 can be challenging if you do not have a good sample script. This can be complex due to the variety of properties that can be involved, such as simple properties, objects, arrays, and arrays of objects. Writing the script in Visual Basic (as described in the "Scripting in Visual Basic" section earlier in this appendix) and using the Locals window can help verify details.

For More Information

Did you find this information useful? Please send your suggestions and comments about the documentation to smsdocs@microsoft.com.