Re: VBScript Mandatory Assignment



Take a look at a booked called SMS 2003 Recipes, http://www.amazon.com/SMS-2003-Recipes-Problem-Solution-Approach/dp/1590597125/ref=pd_bbs_sr_1?ie=UTF8&s=books&qid=1200575811&sr=8-1 it has many vbs scritp that you might be able to modify to do what you need.


"Karl Young" <keyoung@xxxxxxxxxx> wrote in message news:ulCHKZGWIHA.4440@xxxxxxxxxxxxxxxxxxxxxxx
We are not able to go to ConfigMgr 2007 til next year.

I still need the programing solution.

Thank you,
Karl Young

"Garth" <Spam@xxxxxxx> wrote in message news:A8217A37-2B74-44DB-8830-EF3B3283A112@xxxxxxxxxxxxxxxx
It sound like you need maintenance windows setup and for that you should look at ConfigMgr 2007.


"Karl Young" <keyoung@xxxxxxxxxx> wrote in message news:%23nbUVo$VIHA.4768@xxxxxxxxxxxxxxxxxxxxxxx
The below script adds a new mandatory assignment. Is there a way to remove or replace the current mandatory assignment and replace it with a new schedule via script??


The reason is that due to bandwith restrictions, I need to restrict the running of advertisements to a predefined schedule.

I have a script to modify the start time and the expiration date, but I cannot find one that will remove the existing mandatory assignment and replace it with a new date.

There is also a script that will add new mandatory assignment, but not remove the old mandatory assignments in order to replace them below.

Thanks in Advance,
Karl Young
MCSE


' This script was made with the help of Greg Ramsey and his MMS 2005 presenstation on scripting the site server
' This script will modify the local/remote features of an advertisement or all advertisements at a given site


***************Replace Start Time and Expiration time*************

' Declare SMS constants
Const SMSServer = "SMSServer"
Const SMSSiteCode = "SiteCode"
Const ProcessAllAdverts = 0 ' (0/1) ' (WARNING) If set to 1 the script ignores the AdvertID constant and makes the

change to every advertisement found.
Const AdvertID = "XXXXX" ' Specify advertisement ID if ProcessAllAdverts = 0

' RemoteClientFlags (
Const RunLocal_DoNotRunRemote = 40
Const RunLocal_RunRemote = 136
Const RunLocal_DownloadRemote = 72
Const DownloadLocal_DoNotRunRemote = 48
Const DownloadLocal_DownloadRemote = 80



' Set your desired advertisement flag here
myDesiredFlag = RunLocal_RunRemote


' Setup connection to sms server
Set loc = CreateObject("WbemScripting.SWbemLocator")
Set objSMS = loc.ConnectServer(SMSServer, "root\SMS\Site_" & SMSSiteCode)
Dim ObjAdvert

' Check to see if all advertisements are needing modifying or only one
If ProcessAllAdverts = 1 Then
Set objAdvertisements = objSMS.ExecQuery("select AdvertisementID from SMS_Advertisement where SourceSite = '" & _
SMSSiteCode & "' AND RemoteClientFlags <> '" & myDesiredFlag & "'")

'Loop thr all advertisementIDs to get the object reference of each
For Each AdvID in objAdvertisements

' Get direct reference to object using advertisementID's
Set objAdvert = objSMS.Get("SMS_Advertisement.AdvertisementID='" & AdvID.AdvertisementID & "'")

' Set remote client flags and save object
objAdvert.ExpirationTime = datetime
objAdvert.Put_
Next
Else
' Get direct reference to object using advertisementID
Set objAdvert = objSMS.Get("SMS_Advertisement.AdvertisementID='" & AdvertID & "'")



formattedmonth= month(now)

If len(formattedmonth)=1 Then formattedmonth = "0" & formattedmonth
formattedday= day(now)
If len(formattedday)=1 Then formattedday = "0" & formattedday
datetime = year(now) & formattedmonth & formattedday & left(formatdatetime(now, 4),2) &

right(formatdatetime(now, 4),2) & "00.000000+***" 'create a value for the time when the ad should expire.
'Default to + 1/2 year, but it's not enabled.
formattedmonth= month(DateAdd( "d",182, now))
If len(formattedmonth)=1 Then formattedmonth = "0" & formattedmonth
formattedday= day(DateAdd( "d",182, now))
If len(formattedday)=1 Then formattedday = "0" & formattedday
expdatetime = year(DateAdd( "d",182, now)) & formattedmonth & formattedday & left(formatdatetime(DateAdd(

"d",182, now), 4),2) & right(formatdatetime(DateAdd( "d",182, now), 4),2) & "00.000000+***"


'expdatetime = 20080415144400.000000+***

wscript.echo datetime
wscript.echo expdatetime

advertArray = objAdvert.AssignedSchedule
redim preserve advertArray(1)

' Set expirationtime and save object
objAdvert.Presenttime=datetime
objAdvert.AssignedSchedule(advertArray)=datetime
objAdvert.AssignedScheduleEnabled=True
objAdvert.ExpirationTime = expdatetime
objAdvert.Put_



Wscript.echo "Complete"

End If

My Script:

' This script was made with the help of Greg Ramsey and his MMS 2005 presenstation on scripting the site server
' This script will modify the local/remote features of an advertisement or all advertisements at a given site

' Declare SMS constants
Const SMSServer = "HSCSMS01"
Const SMSSiteCode = "HSC"
Const ProcessAllAdverts = 0 ' (0/1) ' (WARNING) If set to 1 the script ignores the AdvertID constant and makes the

change to every advertisement found.
Const AdvertID = "HSC2016D" ' Specify advertisement ID if ProcessAllAdverts = 0

' RemoteClientFlags (
Const RunLocal_DoNotRunRemote = 40
Const RunLocal_RunRemote = 136
Const RunLocal_DownloadRemote = 72
Const DownloadLocal_DoNotRunRemote = 48
Const DownloadLocal_DownloadRemote = 80



' Set your desired advertisement flag here
myDesiredFlag = RunLocal_RunRemote


' Setup connection to sms server
Set loc = CreateObject("WbemScripting.SWbemLocator")
Set objSMS = loc.ConnectServer(SMSServer, "root\SMS\Site_" & SMSSiteCode)
Dim ObjAdvert

' Check to see if all advertisements are needing modifying or only one
If ProcessAllAdverts = 1 Then
Set objAdvertisements = objSMS.ExecQuery("select AdvertisementID from SMS_Advertisement where SourceSite = '" & _
SMSSiteCode & "' AND RemoteClientFlags <> '" & myDesiredFlag & "'")

'Loop thr all advertisementIDs to get the object reference of each
For Each AdvID in objAdvertisements

' Get direct reference to object using advertisementID's
Set objAdvert = objSMS.Get("SMS_Advertisement.AdvertisementID='" & AdvID.AdvertisementID & "'")

' Set remote client flags and save object
objAdvert.ExpirationTime = datetime
objAdvert.Put_
Next
Else
' Get direct reference to object using advertisementID
Set objAdvert = objSMS.Get("SMS_Advertisement.AdvertisementID='" & AdvertID & "'")




************Add Advertisement Script******************

Script from below to add a new mandatory assignment:

It came from 'SMS 2003 Recipies' by Greg Ramsey
and Warren Byle.

strSMSServer = <SMSServer>

strAdvertID = "LAB20016"
'"Occurs every 10 minutes beginning now()"
'For advStartTime, 'Now()' is used to get the current
'date/time of the system. A properly fomatted date/time would
'just fine here also: e.g., "12/02/2006 12:59 AM"
advStartTime = Now()

Set objLoc = CreateObject("WbemScripting.SWbemLocator")
Set objSMS= objLoc.ConnectServer(strSMSServer, "root\sms")
Set Results = objSMS.ExecQuery _
("SELECT * From SMS_ProviderLocation WHERE ProviderForLocalSite = true")
For each Loc in Results
If Loc.ProviderForLocalSite = True Then
Set objSMS = objLoc.ConnectServer(Loc.Machine, "root\sms\site_" & _
Loc.SiteCode)
strSMSSiteCode = Loc.Sitecode
end if
Next

'''''''''''''Schedule Token Information
'Create a new instance of SMS_ST_RecurInterval
Set advNewRecurToken = objSMS.Get("SMS_ST_RecurInterval"). _
SpawnInstance_()
advNewRecurToken.MinuteSpan=10
advNewRecurToken.StartTime = ConvertToWMIDate(advStartTime)
'''''''''''''END Schedule Token Information

retval = AddSchedToken(advNewRecurToken,strAdvertID)

Function AddSchedToken(objSchedToken, strAdvertID)
'enlarge the current schedule array by 1
Set objAdvert=objSMS.Get _
("SMS_Advertisement.AdvertisementID='" & strAdvertID & "'")
advertArray = objAdvert.AssignedSchedule
onemore = ubound(advertArray) + 1
redim preserve advertArray(onemore)
objAdvert.AssignedSchedule = advertArray
'add the new assignment
objAdvert.AssignedSchedule(onemore) = objSchedToken
objadvert.AssignedScheduleEnabled = True
AddSchedToken = objAdvert.Put_
End Function

Function ConvertToWMIDate(strDate)
'Convert from a standard date time to wmi date
'4/18/2005 11:30:00 AM = 2005041811300.000000+***
strYear = year(strDate):strMonth = month(strDate)
strDay = day(strDate):strHour = hour(strDate)
strMinute = minute(strDate)
'Pad single digits with leading zero
if len(strmonth) = 1 then strMonth = "0" & strMonth
if len(strDay) = 1 then strDay = "0" & strDay
if len(strHour) = 1 then strHour = "0" & strHour
if len(strMinute) = 1 then strMinute = "0" & strMinute
ConvertToWMIDate = strYear & strMonth & strDay & strHour _
& strMinute & "00.000000+***"
end function







.



Relevant Pages

  • VBScript Mandatory Assignment
    ... The below script adds a new mandatory assignment. ... Const SMSSiteCode = "SiteCode" ... change to every advertisement found. ...
    (microsoft.public.sms.admin)
  • Re: VBScript Mandatory Assignment
    ... I have following script, ... ' This script will modify the local/remote features of an advertisement ... Const SMSSiteCode = "SiteCode" ...
    (microsoft.public.sms.admin)
  • Re: VBScript Mandatory Assignment
    ... I have a script to modify the start time and the expiration date, ... ' This script will modify the local/remote features of an advertisement ... Const SMSSiteCode = "SiteCode" ... ' Get direct reference to object using advertisementID's ...
    (microsoft.public.sms.admin)
  • Re: VBScript Mandatory Assignment
    ... I have a script to modify the start time and the expiration date, but I cannot find one that will remove the existing mandatory assignment and replace it with a new date. ... ' This script will modify the local/remote features of an advertisement or all advertisements at a given site ... Const SMSSiteCode = "SiteCode" ...
    (microsoft.public.sms.admin)
  • Re: Vbscript to modify user object in AD
    ... if so you can use the following script to modify the ... Const ADS_PROPERTY_UPDATE = 2 ... 'Setup to get all the users in the specified OU from above. ...
    (microsoft.public.scripting.vbscript)

Loading