SMS脚本节选四:创建,修改,删除SMS对象

    技术2022-05-11  62

    The processes by which SMS objects are managed can be divided into the following categories: 

    Creating an SMS objectModifying an SMS objectDeleting an SMS objectCalling a method on an SMS object

    For more information on creating and deleting WMI objects, see the text xmlns="http://ddue.schemas.microsoft.com/authoring/2003/5">WMI SDK.

    To create an SMS object

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

    Create an instance of an SMS object by using the text xmlns="http://ddue.schemas.microsoft.com/authoring/2003/5">SpawnInstance method supported by the desired class. For example, to create an instance of a package object (SMS_Package), use the following code:

    Set objNewPackage = objSWbemServices.Get("SMS_Package").SpawnInstance_()

    Populate the required properties. For example, the following code sets the properties for a package:

    objNewPackage.Name = "Package Name" objNewPackage.Description = "A new package" objNewPackage.PkgSourceFlag = 2 objNewPackage.PkgSourcePath = "C:/temp"

    Save the SMS object by using the text xmlns="http://ddue.schemas.microsoft.com/authoring/2003/5">Put_ method supported by the SMS object class. For example, the following line of code puts or saves a package:

    objNewPackage.Put_

    To modify an SMS object

    Get the instance of the required SMS object by using the Windows Script Host GetObject method and supplying the path to the required object. For example, to get an instance of an advertisement object (SMS_Advertisement) identified as 99920002, use the following code.

    Set objAdvertisement = GetObject( "WinMgmts:root/SMS/site_999:SMS_Advertisement.AdvertisementID='99920002'")

    Set the required properties of the SMS object. To enable the assigned schedule for an advertisement object, set the AssignedScheduledEnabled property to True, as in the following example:

    objAdvertisement.AssignedScheduleEnabled=True

    Update the SMS object by using the SMS object class Put method. For example, to update the advertisement opened in step 1, use the following code:

    objAdvertisement.Put_

    To delete an SMS object

    Get the instance of the required SMS object by using GetObject and supplying the path to the required object. For example, to get an instance of an advertisement object (SMS_Advertisement) identified as 99920003, use the following code:

    Set objAdvertisement = GetObject( "WinMgmts:root/SMS/site_999:SMS_Advertisement.AdvertisementID='99920003'")

    Delete the SMS object instance by using the SMS object class text xmlns="http://ddue.schemas.microsoft.com/authoring/2003/5">Delete_ method. For example, to delete the advertisement object opened in step 1, use the following code:

    objAdvertisement.Delete_

    最新回复(0)