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:


<#
.SYNOPSIS
Backup all task sequences to disk greater than $minDate
.DESCRIPTION
TS backup will fail if TS name has special characters not allowed, edit sitecode and destinationpath
.PARAMETER <Parameter_Name>
None
.INPUTS
None
.OUTPUTS
None
.NOTES
Version: 4.0
Author: dpadgett/https://execmgr.net
Creation Date: 270617
Purpose/Change: Initial script development
.EXAMPLE
None
#>
##Modify ConfigMgr Path if necessary##
Import-Module 'D:\Program Files\Microsoft Configuration Manager\AdminConsole\bin\ConfigurationManager.psd1'
##Enter Site Code Below###
CD XXX:
[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\$exportname.zip" -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:
Advertisement

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:

WordPress.com Logo

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

Facebook photo

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

Connecting to %s