by Phil Wilcock (philw@1e.com)
This tiny VB script addresses a common issue which is increasingly faced by SMS Administrators, namely the ever shrinking time window available for software distribution. Works for either SMS2.0 or SMS2003
Supposing you need to push out a package to your machines – but you want it to become available at midnight, and then stop it from executing after 6am.
You could of course create a mandatory assignment for the Advertisement at 00:00, and then have it expire at 06:00, but what if you want this to happen every night? You would have to create a new schedule each day which is an overhead you could well do without.
So, this little snippet of code, when executed by Task Scheduler will take care of the enabling or disabling of the Advertisement so that with a single Assigned schedule you can be sure that your SMS Clients will only ever attempt to install the software between the hours of 12:00 and 06:00 each day.
Here’s the workflow…
- Create the Advertisement for the package that you want to run. Let’s suppose it has an Advertisement ID of AAA99999
- Make the Advertisement available after midnight, and also create an Assigned Schedule for midnight. All of the targeted systems that are turned on at this time will then run the software.
- Using Windows Task Scheduler, create a task that will run at 06:00 every day to run the script. This will disable the Advertisement assigned schedule so that any systems that are turned on after that time will not run the advertisement.
- Using Task Scheduler, create a task that will run at 00:00 (midnight) each day – starting the DAY AFTER the advertisement is first scheduled (we don’t want to disable it before it’s started do we!?)
The result of this will be that the advertisement will only run on your SMS clients between 00:00 and 06:00 each day with no further intervention. Ideal if you have a large package that you want to push out over a few days, or something that is run frequently.
Note that you can't see this flag (AssignedScheduleEnabled) in the UI
Code
dim instance
Set instance = GetObject("WinMgmts:root\SMS\site_XXX:SMS_Advertisement.AdvertisementID='ABC99999'")
if instance.AssignedScheduleEnabled=True Then
instance.AssignedScheduleEnabled=False
instance.Put_
else
instance.AssignedScheduleEnabled=True
instance.Put_
end if