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:

Get-WmiObject -ComputerName $CompName -Namespace "root\CCM\Policy\Machine\ActualConfig" -Class "CCM_SoftwareDistribution" | ForEach-Object {
$PackageName = $_.PKG_Name
$AdvID = $_.ADV_AdvertisementID
$PRFDisable = $_.PRG_PRF_Disabled
if ($PRFDisable -eq $false){$AdvListGrid.rows.add($PackageName,$AdvID)

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:

$strQuery = "Select * from CCM_Scheduler_ScheduledMessage where ScheduledMessageID like '" + $AdvID + "%'"
$objSMSSchID = Get-WmiObject -Query $strQuery -Namespace root\ccm\policy\machine\actualconfig -computername $CompName
foreach ($instance in $objSMSSchID){$strScheduleID = $instance.ScheduledMessageID}

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:

$strQuery = "Select * from CCM_SoftwareDistribution where ADV_AdvertisementID='" + $AdvID + "'"
Get-WmiObject -ComputerName $CompName -Namespace "root\CCM\Policy\Machine\ActualConfig" -Query $strQuery | ForEach-Object {
$_.ADV_MandatoryAssignments = "True"
$_.ADV_RepeatRunBehavior = "RerunAlways" 

Now we are finally ready to re-run the deployment!

$WMIPath = "\\" + $CompName + "\root\ccm:SMS_Client"
$SMSwmi = [wmiclass] $WMIPath

It’s as simple as that!

Last edited Mar 10, 2013 at 9:25 PM by Ryan2065, version 1


No comments yet.