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. 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.AdvertisementNamenext

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.Namenext

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.AdvertisementNamenext

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



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值