Backup SCCM Task Sequences With Scheduled Task+Powershell

Hi All,

I needed a basic script to backup my task sequences on a schedule. Using PowerShell to back up your Task Sequences is a much faster way than manually doing it through the console.

See below code:

Backup all task sequences to disk greater than $minDate
TS backup will fail if TS name has special characters not allowed, edit sitecode and destinationpath
.PARAMETER <Parameter_Name>
Version: 4.0
Author: dpadgett/
Creation Date: 270617
Purpose/Change: Initial script development
##Modify ConfigMgr Path if necessary##
Import-Module 'D:\Program Files\Microsoft Configuration Manager\AdminConsole\bin\ConfigurationManager.psd1'
##Enter Site Code Below###
[datetime]$minDate = "1/1/2017 00:00:00 AM"
$ts = Get-CMTaskSequence | Where-Object {$_.SourceDate -gt $minDate}
$time = get-date -format ddMMyyyy
New-Item -Path "E:\Source\ITS\TSBackups\Backups\$time" -ItemType Directory
foreach ($t in $ts){
$path = "E:\Source\ITS\TSBackups\Backups"
$exportname = $t.Name
Export-CMTaskSequence -TaskSequencePackageId $t.PackageID -ExportFilePath "$path\$time\$" -Verbose

view raw

backup ts

hosted with ❤ by GitHub

Save the code above to a ps1 file, put on your SCCM server and set up a scheduled task to run the following command: powershell.exe -executionpolicy bypass -file “file.ps1”
End Result:

2 thoughts on “Backup SCCM Task Sequences With Scheduled Task+Powershell

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s