How to Read SMS Objects

Published : April 11, 2005

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.

See How SMS Uses WMI for further information.

On This Page

To get a collection of all instances of an SMS object by using a WQL query
To get a collection of a specific set of SMS objects by using a WQL query
To get a collection of all instances of an SMS object using the InstancesOf method
To get a single instance of an SMS object using the GetObject method.
See Also

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

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

  2. 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. 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. Connect to an SMS Provider, and get the SWbemServices object.

  2. 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. 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. Connect to an SMS Provider, and get the SWbemServices object.

  2. 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. 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. 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. Read the SMS object:

    Wscript.echo objAdvertisement.AdvertisementName

See Also

Tasks

How to Connect to an SMS Provider

How to Read Lazy Properties

Concepts

SMS Objects

Other Resources

Retrieving Managed Resources Using WMI