Importing Task Sequences into SCCM/ConfigMgr

The Problem
One of my probably mostly used scripts is a VBScript that monitors for any changes on Task Sequences in SCCM and exports a copy for backup purposes when an updated task sequence is saved. Please see https://maikkoster.com/versioning-monitoring-sccm-task-sequences-update-for-sccm-2012/ for further details about the script itself. Even it has been written for SCCM 2007, it still works for 2012 and above. The “only” drawback is, that Microsoft changed the export format between the versiona 2007 and 2012. In 2007 and below, the exported Task Sequence was a plain xml file. Very easy to handle. And even better, very easy to adjust if it comes to replacing packages etc.
In version 2012 and above though, this simple xml file has been replaced with a rather complex zipped file. It still contains an xml file with the Task Sequence itself, but can also contain referenced packages, applications and a lot of additional information. This has for sure its advantages. However, for plain backup purposes, I personally still prefer the plain xml file. Also automated synching of Task Sequences between different SCCM environments or moving changes from one Task Sequence to a different Task Sequence is way easier when using a plain xml file.
So while I was using this method quite regularly at work I actually never publicly published a script that would allow you to import those task sequence xml files, that are generated by the above mentioned VBScript, back into a SCCM 2012+ environment. Shame on me, but here it is (finally)
The Solution
I finally published a cleaned up version of a script, that will allow you to import a Task Sequence that was exported via the above mentioned script and either replace an existing Task Sequence or create a new Task Sequence package.
Find the full script at https://github.com/MaikKoster/ConfigMgr/blob/master/TaskSequence/Standalone/Import-TaskSequence.ps1
Just to point this out again, this script won’t be able to import Task Sequences exported from the SCCM 2012+ console (It will be able to consume the object.xml file from this export zip file though)! Just plain xml files as created by the above mentioned monitoring script or the PowerShell equivalent which will allow you to still export plain xml in SCCM 2012+.
How to use it
The script comes with (hopefully) proper documentation. So calling the default
1 |
Get-Help .\Import-TaskSequence.ps1 -detailed |
should give you a start.
First, it requires the Path to the xml file. In addition you need to supply the ID (Task Sequence PackageID) or the Name of the Task Sequence that you would like to have replaced with the content of the xml file. I pesonally wouldn’t use the Name parameter for this as it might not be unique, but that’s just me.
YES, this will replace the specified Task Sequence, so be careful and don’t execute this if you don’t know what you are doing. I will not be liable for any damages. Luckily for you, if you use my above mentioned script, it will automatically create a backup of the Task Sequence for you 😉 In addition this operation is configured with High impact. So on default, you will be asked to continue.
1 |
.\Import-TaskSequence.ps1 -Path "C:\Backup\TST00001.xml" -ID "TST00001" |
If you don’t want to be asked for confirmation, you can either set the $ConfirmPreference variable to “None”
1 2 |
$ConfirmPreference = "None" .\Import-TaskSequence.ps1 -Path "C:\Backup\TST00001.xml" -ID "TST00001" |
or call the script with -Confirm:$false.
1 |
.\Import-TaskSequence.ps1 -Path "C:\Backup\TST00001.xml" -ID "TST00001" -Confirm:$false |
The script also supports the standard -WhatIf parameter. If set, it will only show what it would do, without implementing any changes.
1 |
.\Import-TaskSequence.ps1 -Path "C:\Backup\TST00001.xml" -ID "TST00001" -WhatIf |
If you don’t want to replace an existing Task Sequence, supply the Create switch. If the Create switch is supplied, you have to specify the Name as well and can’t use the ID and can optionally supply a Description. The script will create a new Task Sequence package based on the Task Sequence of the xml file. Comes in handy for copying task sequences as well. If you want to know the PackageID of the new Task Sequence Package, use the PassThru switch, as without it, the script won’t output anything except of error messages if something fails.
1 |
.\Import-TaskSequence.ps1 -Path "C:\Backup\TST00001.xml" -Create -Name "Save the World" |
On default, the script assumes to be executed on the SCCM Site server or SCCM Provider Server using the credentials of the current user. If you need to adjust this as you are maybe using this script from a different computer or need to use different credentials (e.g. when migrating a task sequence between different environments), use the ProviderServer, SiteCode and Credential parameters.
1 |
.\Import-TaskSequence.ps1 -Path "C:\Backup\TST00001.xml" -Create -Name "Save the World" -ProviderServer "CM01" -SiteCode "TST" -Credential (Get-Credential) |
Finally, as mentioned already the script is quiet on default as it’s primarily meant for automation. If you want to get any feedback, you can set the PassThru parameter which will return the udpated Task Sequence Package. In addition you can set the ShowProgress switch to show the progress of the import process, which might be helpful over slow WAN connections. And it also makes use of the Verbose switch, that gives you some detailed information while it’s executing
1 |
.\Import-TaskSequence.ps1 -Path "C:\Backup\TST00001.xml" -Create -Name "Save the World" -Verbose -ShowProgress -PassThru |
There are actually two versions of this script. The one referenced above is a standalone version, created by the script from my recent post “Creating standalone PowerShell scripts – automatically merging module components into scripts”. The “real” script is referencing a SCCM (ConfigMgr) module that I’ve published at Github as well. As I regularly apply changes to this module, it might be better to use the standalone version as this will be updated every time there has been a change on a function used by it. But that’s up to you.
Standalone Version: https://github.com/MaikKoster/ConfigMgr/blob/master/TaskSequence/Standalone/Import-TaskSequence.ps1
“Module” Version: https://github.com/MaikKoster/ConfigMgr/blob/master/TaskSequence/Import-TaskSequence.ps1
ConfigMgr Module: https://github.com/MaikKoster/ConfigMgr/blob/master/Module/ConfigMgr.psm1
As always, I appreciate any feedback.
2 Responses
[…] 29.03.2016: Published new script to import the Task Sequence xml files generate by this script back to SCCM 2012 and […]
[…] In the last blog post I showed a script that would allow you to import a Task Sequence from an xml file as the ones being created by the Task Sequence monitoring script (see https://maikkoster.com/versioning-monitoring-sccm-task-sequences/ for details). […]