This script shows how to set the SMS site comment for a secondary site. The script demonstrates how a script that manipulates site settings at one site can change the properties for another site that reports to the first site, even if the other site reports indirectly to the first site.

The ConnectServer line connects to the parent site, but the line that refreshes the script’s copy of the site control file and the line that gets the site definition both get the child site’s site control file. When the changes are committed, the child site is again specified.

Example

Dim objSWbemLocator
Dim objSWbemServices
Dim objSWbemContext
Dim LocalSiteCode
Dim SiteToChange

LocalSiteCode = "SITECODE"
SiteToChange = "SITECODEOFSITETOCHANGE"

Set objSWbemLocator = CreateObject("WbemScripting.SWbemLocator")
Set objSWbemServices = objSWbemLocator.ConnectServer( , "root\sms\site_" & LocalSiteCode )

Set objSWbemContext = CreateObject("WbemScripting.SWbemNamedValueSet")
objSWbemContext.Add "SessionHandle", objSWbemServices.ExecMethod("SMS_SiteControlFile", "GetSessionHandle").SessionHandle
objSWbemServices.ExecMethod "SMS_SiteControlFile.Filetype=1,Sitecode=""" & SiteToChange & """", "Refresh", , , objSWbemContext
Set WbemInst = objSWbemServices.Get("SMS_SCI_SiteDefinition.Filetype=1,Itemtype='Site Definition',Sitecode='" & SiteToChange & "',ItemName='Site Definition'", , objSWbemContext)

proparray = WbemInst.props
WScript.Echo sitecode & " site comment: " & proparray(0).Value1
proparray(0).Value1 = "Set from script"
WbemInst.props = proparray

WbemInst.Put_ , objSWbemContext
objSWbemServices.ExecMethod "SMS_SiteControlFile.Filetype=1,Sitecode=""" & SiteToChange & """", "Commit", , , objSWbemContext
objSWbemServices.Get("SMS_SiteControlFile").ReleaseSessionHandle objSWbemContext.Item("SessionHandle").Value

Compiling the Code

  • Requires Windows 2000 Server SP2 or later.

  • Requires an SMS 2003 Site Server.

See Also