Here is a simple PowerShell script that helps you to export a list of all task sequences in your configuration manager server to a folder.
These exported task sequences can be then imported to another environment (Dev to PROD) and get things moving instead of creating them from scratch.
Exporting the task sequence can be done using GUI or scripting (Powershell).
Powershell would be nicer to export multiple task sequence’s in an automated schedule.
we can make use of Configuration Manager cmdlets and scripts by using the Configuration Manager console or by using a Windows PowerShell session.
When you run Configuration Manager cmdlets by using the Configuration Manager console, your session runs in the context of the site.
we will use built-in PowerShell cmdlet to export the list of all task sequences with its dependencies exclude the content of it to a shared folder.
Export-CMTaskSequence help to exports a Configuration Manager task sequence.
With this cmdlet, we will create simple powershell script and export all task sequences.
we will get list of all task sequences using Get-CMTaskSequence and export it.
If you want to export the task sequence with content, change -WithContent to true and -WithDependence $true
Change the folder path where to save the task sequence files in zip format.
<#
.DESCRIPTION
Exports all configuration manager task sequences without content/dependencies.
Author: Eswar Koneti
Version: 1.0
Date: 24/Jan/2020
#>
#Get the script start time
$starttime=get-date
Write-host "Script started at $starttime"
#import configuration manager powershell module
try {
Import-Module (Join-Path $(Split-Path $env:SMS_ADMIN_UI_PATH) ConfigurationManager.psd1)
}
catch [System.Exception] {
Write-Warning "Unable to load the Configuration Manager Powershell module from $env:SMS_ADMIN_UI_PATH" ; break
}
#get the sitecode
$SiteCode = Get-PSDrive -PSProvider CMSITE
Set-Location -Path "$($SiteCode.Name):\"
#get list of all task sequences
$ts = Get-CMTaskSequence | select Name
foreach($name in $ts)
{
#Replace any unsupported characters with empty space for folder name
$tsname=$name.Name.replace(":","").replace(",","").replace("*","").replace("?","").replace("\","").replace("\","").replace("<","").replace(">","")
#export the task sequences to share folder
Export-CMTaskSequence -Name $name.name -WithDependence $false -withContent $false -ExportFilePath ("\\servername\Task sequence\"+$tsname+ ".zip") -Force
}
#Get script end time
$endtime=Get-date
#Get the script execution time (total)
$Scripttime=($endtime-$starttime).Seconds
write-host "Script ended at $endtime with execution time of $Scripttime seconds"
if you want to export specific task sequence, please refer https://docs.microsoft.com/en-us/powershell/module/configurationmanager/export-cmtasksequence?view=sccm-ps
Recommend reading :
Get started with Configuration Manager cmdlets https://docs.microsoft.com/en-us/powershell/sccm/overview?view=sccm-ps