Before connecting to the SMS Provider for a local or remote SMS site server, you first need to locate the SMS Provider for the site server. The SMS Provider can be either local or remote to the SMS site server you are using. The WMI class SMS_ProviderLocation is present on all SMS site servers, and one instance will contain the location for the SMS site server you are using.
You can connect to the SMS Provider on an SMS site server by using the WMI text xmlns="http://ddue.schemas.microsoft.com/authoring/2003/5">SWBemLocator object or by using the Windows Script Host GetObject method. Both approaches work equally well on local or remote connections, with the following limitations:
- You must use SWbemLocator if you need to pass user credentials to a remote computer.
- You cannot use SWBemLocator to explicitly pass user credentials to a local computer.
There are several different syntaxes that you can use to make the connection, depending on whether the connection is local or remote. The following procedures provide two common variations. After you are connected to the SMS Provider, you will have an text xmlns="http://ddue.schemas.microsoft.com/authoring/2003/5">SWBemServices object that you use to access SMS objects.
To connect to an SMS Provider by using SWbemLocator
-
Connect to the local SWbemLocator object:
set objSWbemLocator = CreateObject("WbemScripting.SWbemLocator")
-
Connect to a known SMS site server. If the computer name is a remote computer, you can pass the user name and password. Alternatively, you can authenticate using the current user's credentials by removing the user name and password parameters. If the computer name is the local computer, you must remove the user name and password because these will not be accepted. You can also change the computer name to "." if you want to connect to the local computer.
set objSWbemServices= objSWbemLocator.ConnectServer _ ("ComputerName", "root/sms","username","password")
-
Locate the SMS Provider for the SMS site by inspecting the SMS_ProviderLocation WMI class. For the SMS_ProviderLocation instance where the ProviderForLocalSite property is true, the object's Machine and SiteCode properties give the location of the SMS Provider for the SMS site server you are connected to. If the account running the script on the local computer has appropriate privileges, the user name and password parameters can be omitted.
Set ProviderLoc = objSWbemServices.InstancesOf("SMS_ProviderLocation") For Each Location In ProviderLoc If Location.ProviderForLocalSite = True Then Set objSWbemServices = objSWbemLocator.ConnectServer _ (Location.Machine, "root/sms/site_" + Location.SiteCode,"username","password") End If Next
-
Continue using the objSWbemServices object to access SMS objects.
To connect to a remote SMS Provider by using the GetObject method
-
Connect to a known SMS site server by using GetObject. In this example, authentication is set to impersonate. If you are connecting to the local computer, you can change SERVERNAME to ".".
Set objSWbemServices = GetObject("winmgmts:{impersonationLevel=impersonate}!//SERVERNAME/root/sms/site_SITECODE") if err.number<>0 then wscript.echo "WBemServices connection failed" wscript.quit end if
-
Continue using the objSWbemServices object to access SMS objects.
Security
Using script to pass the user name and password is a security risk and should be avoided where possible.