The first thing you need to Rerun a package or task sequence is get the Advertisement ID. In my deployment tool, the advertisement ID is fed to the script through the console. In my device tool, I give the user a list of Advertisements and have them
pick one. I get the list of Advertisements with this code:
I only want to get packages or task sequences that are enabled because I figure the disabled ones are disabled for a reason.
After I have the Advertisement ID, I must get the Scheduled Message ID. The WMI method we will use to re-run the advertisement needs the Scheduled Message ID, not the Advertisement ID. You can get the Scheduled Message ID from
the server (it doesn’t change from computer to computer) or from the computer. I chose to just get it from the computer:
= "Select * from CCM_Scheduler_ScheduledMessage where ScheduledMessageID like '"
Now that we have the Scheduled Message ID, we can rerun any package or task sequence that is a mandatory deployment and set to re-run always. When we tell the computer to re-evaluate this deployment,
it goes off of what the computer has, not off of what the server has. Because of this, we can actually change these values to match what they need to be to re-run the deployment:
= "Select * from CCM_SoftwareDistribution where ADV_AdvertisementID='"
Now we are finally ready to re-run the deployment!
It’s as simple as that!