SMS脚本节选一:连接到SMS Provider

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

  1. Connect to the local SWbemLocator object:

    set objSWbemLocator = CreateObject("WbemScripting.SWbemLocator")
  2. 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")
  3. 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
  4. Continue using the objSWbemServices object to access SMS objects.

To connect to a remote SMS Provider by using the GetObject method

  1. 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
    
  2. 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.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值