The dates and times that SMS advertisement objects (SMS_Advertisement) can be assigned to run are stored as an array of objects. The objects are based on one of the classes, which are based on the SMS_ScheduleToken class. Adding or removing assignments requires adding or removing objects from that array. This example shows how to add an assignment to an existing advertisement.

Some properties in other SMS classes are also arrays of objects. The technique described in this example can be used in other situations.


Dim objSWbemLocator
Dim objSWbemServices
Dim ProviderLoc
Dim AdvertisementID
Dim Location
Dim objAdvertisement
Dim i
Dim newST
Dim array()
AdvertisementID="99999999" 'Provide the required advertisement identifier here

'Connect to provider namespace for local computer.
Set objSWbemLocator = CreateObject("WbemScripting.SWbemLocator")

Set objSWbemServices= objSWbemLocator.ConnectServer(".", "root\sms")

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)
		End If

Set objAdvertisement = objSWbemServices.Get("SMS_Advertisement.AdvertisementID='" & AdvertisementID & "'")

'Copy the current assigned schedule array to a local array that is one 
'bigger than the current assigned schedule array.

redim array( UBound(objAdvertisement.AssignedSchedule)+1 )
For i=0 to UBound( objAdvertisement.assignedSchedule )
  Set array(i) = objAdvertisement.AssignedSchedule(i)

'Create an assignment.
Set newST = objSWbemServices.Get("SMS_ST_RecurInterval").SpawnInstance_()
'Add the new assignment to the end of the local array.
Set array( UBound(array) ) =newST

objAdvertisement.AssignedSchedule = array


Compiling the Code

  • Requires Windows 2000 Server SP2 or later.

  • Requires an SMS 2003 Site Server.

See Also