MSEndpointMgr
Home ยป Microsoft Endpoint Manager ยป ConfigMgr ยป Re-run Task Sequence with PowerShell

Re-run Task Sequence with PowerShell

Today I had to re-run a task sequence which had failed the first time. I figured that it could probably be done with PowerShell. After reading Steve Rauchi’s blog post on how to remove the scheduler history object, I started out trying to accomplish the same thing with PowerShell.

In the Configuration Manager 2012 console, we need to locate what Package ID the task sequence has. The Package ID can be found under Software Library – Operating Systems – Task Sequences in the Package IDcolumn for the task sequence in question. In this case the Package ID was C01000D0. We will locate the instance in WMI by searching for the ScheduleID property.

Let start off with the code to locate the instance in WMI containing the Package ID. Launch PowerShell with administrative rights, and type:

Get-WmiObject -Namespace "root\ccm\scheduler" -Class ccm_scheduler_history | where {$_.ScheduleID -like "*C01000D0*"} | ft ScheduleID

This should give the following results:

ScheduleID
----------
P012000E-C01000D0-6F6BCC28

Now that we have the instance, we need to delete it. Modify the previous command so it looks like:

Get-WmiObject -Namespace "root\ccm\scheduler" -Class ccm_scheduler_history | where {$_.ScheduleID -like "*C01000D0*"} | Remove-WmiObject

The instance should now be deleted. Run the first command again, to verify the ouput is empty. Once that is done, we need to restart the CcmExec service. Run the following command:

Get-Service | where {$_.Name -eq "CCMExec"} | Restart-Service

Once the service has restarted, the task sequence should kick off again automatically.

(12928)

Nickolaj Andersen

Chief Technical Architect and Enterprise Mobility MVP since 2016. Nickolaj has been in the IT industry for the past 10 years specializing in Enterprise Mobility and Security, Windows devices and deployments including automation. Awarded as PowerShell Hero in 2015 by the community for his script and tools contributions. Creator of ConfigMgr Prerequisites Tool, ConfigMgr OSD FrontEnd, ConfigMgr WebService to name a few. Frequent speaker at conferences such as Microsoft Ignite, NIC Conference and IT/Dev Connections including nordic user groups.

9 comments

  • I wish there were a way to run a task sequence immediately, even for the first time. When I add a computer to a collection with a TS deployment it can take a very long time before the TS is available in the software center. This is true even when I download machine policy manually in the CM Control Panel.
    Gary

  • Tried to use the same way for Packages and Programs. It should work, but after SMS agent host service restart, I’ve got “A duplicate execution request is found for program …” in execmgr.log.
    It would be great if you have the key to solve it, Nikolaj :))

  • I just can’t get it to work ๐Ÿ™ We’re running SCCM 2012 R2 on a Windows 8.1 workstation.

    Removing the Task sequence ID works, but when i restart the service nothing happens and after a few seconds the Task Sequence ID is available again.

    The Re-run Task Sequence Tool has the same effect ๐Ÿ™ Any ideas what goes wrong?

    • I’m having the same problem, just comes back right after. Even tried pulling machine from collection, after it was gone from Software centre ran script, all was good, re-add machine to collection, once policy hit machine, it was once again “Installed” and in the WMI as well…

    • Hi Jim,

      Thanks for the kind words! Have you checked out the prerequisites script that I just released? It’s definitely worth checking out.

      Regards,
      Nickolaj

Sponsors

Subscribe

Do you want to be notified of new posts on our site?

Please enter your email address below:

Categories

MSEndpointMgr.com use cookies to ensure that we give you the best experience on our website.