SMS脚本节选二:如何读取SMS对象

There are several ways to read SMS objects from the SMS Provider with WMI. In general, you need to get either a specific SMS object instance or a collection of SMS object instances. The procedures in this topic demonstrate several common techniques for getting SMS objects and fall into the following categories:

  • Getting a collection of all instances of a SMS object.

  • Getting a collection of a specific set of SMS objects.

  • Getting a single instance of a SMS object.

To get a collection of all instances of an SMS object by using a WQL query

  1. <content xmlns="http://ddue.schemas.microsoft.com/authoring/2003/5"></content>

    Connect to an SMS Provider, and get the SWbemServices object.

  2. <content xmlns="http://ddue.schemas.microsoft.com/authoring/2003/5"></content>

    Get a collection of SMS objects by using the WBemServices.ExecQuery method. ExecQuery returns the collection as an SWbemObjectSet object. The following example gets all advertisement (SMS_Advertisement) objects:

    set colAdvertisements = objSWbemServices.ExecQuery( "Select * From SMS_Advertisement")
  3. <content xmlns="http://ddue.schemas.microsoft.com/authoring/2003/5"></content>

    Read the SMS objects:

    for each objAdvertisement in colAdvertisements
        wscript.echo objAdvertisement.AdvertisementName
    next

To get a collection of a specific set of SMS objects by using a WQL query

  1. <content xmlns="http://ddue.schemas.microsoft.com/authoring/2003/5"></content>

    Connect to an SMS Provider, and get the SWbemServices object.

  2. <content xmlns="http://ddue.schemas.microsoft.com/authoring/2003/5"></content>

    Get a collection of the desired SMS objects by using the WBemServices.ExecQuery method. ExecQuery returns the collection as an SWbemObjectSet object. This example gets all resources that are members of the All Windows Server 2003 collection.

    set colCollection=objSWbemServices.ExecQuery("SELECT * FROM SMS_FullCollectionMembership WHERE CollectionID='SMS000FS'" )
  3. <content xmlns="http://ddue.schemas.microsoft.com/authoring/2003/5"></content>

    Read the SMS objects:

    for each objCollectionMember in colCollection
        wscript.echo objCollectionMEmber.Name
    next

To get a collection of all instances of an SMS object using the InstancesOf method

  1. <content xmlns="http://ddue.schemas.microsoft.com/authoring/2003/5"></content>

    Connect to an SMS Provider, and get the SWbemServices object.

  2. <content xmlns="http://ddue.schemas.microsoft.com/authoring/2003/5"></content>

    Get a collection of SMS objects using the WBemServices.InstancesOf method. This example gets all advertisement (SMS_Advertisement) objects.

    set colAdvertisements = WbemServices.InstancesOf("SMS_Advertisement")
  3. <content xmlns="http://ddue.schemas.microsoft.com/authoring/2003/5"></content>

    Read the SMS objects:

    for each objAdvertisement in colAdvertisements
        wscript.echo objAdvertisement.AdvertisementName
    next

To get a single instance of an SMS object using the GetObject method.

  1. <content xmlns="http://ddue.schemas.microsoft.com/authoring/2003/5"></content>

    Get the required instance of the SMS object by using GetObject. The instance must be identified by one of its key properties. This example gets an instance of the advertisement with an advertisement identifier of B2K2001. In this example, GetObject returns an SWbemObject object.

    Set objAdvertisement = GetObject( "WinMgmts:root\SMS\site_SITECODE:SMS_Advertisement.AdvertisementID='ADVERTISEMENTID'")
  2. <content xmlns="http://ddue.schemas.microsoft.com/authoring/2003/5"></content>

    Read the SMS object:

    Wscript.echo objAdvertisement.AdvertisementName

你可能感兴趣的:(windows,脚本,Microsoft)