Restoring Task Sequences the easy way

A while ago I was asked if it was possible to restore a Task Sequence. My first reaction was “of course”. But digging into the problem I quickly realized I would need to restore the entire ConfigMgr database. And because it was a primary site under a CAS I was a bit reluctant. The immediate need for the restore went away but it made me think of a more easy way of restoring a Task Sequence. This is what I came up with.

The backup of the database is being done from within SQL Server with a maintenance plan. I already added a SQL Agent Job to this Maintenance Plan so what if I could add a second job to create an export of all the excisting Task Sequences?

The first step was to create the code to export all Task Sequences.

import-module ($Env:SMS_ADMIN_UI_PATH.Substring(0,$Env:SMS_ADMIN_UI_PATH.Length-5) + ‘\ConfigurationManager.psd1’)
Set-Location CM0:
Foreach ($ts in Get-CMTaskSequence) {
    $ZipName = "\\server\share$\task-sequences\" + $ts.Name + ".zip"
    Export-CMTaskSequence -Name $ts.Name -ExportFilePath $ZipName

Then add this code as a Powershell script to a SQL Agent Job. Make sure that the service account that is running the SQL job has appropiate permissions in ConfigMgr.

To make it work I had to logon to the ConfigMgr console once with the SQL service account. This makes sure that all registry keys are there…

Now everytime that my SQL backup runs it also makes a zip file of every Task Sequence. Include the folder in your file level backup to add retention because the Export-CMTaskSequence cmdlet will overwrite existing zip files.

You could also use WMI Event Scripting to create a backup everytime a Task Sequence is changed… But that is something for the future.

Creating Azure JSON templates with Visual Studio Code

Because I am practising for the 70-533 exam I thought I could try to create some Azure JSON templates. For this I wanted to use Visual Studio Code. On the Azure documentation site there are some great examples to get you started.

After installing Visual Studio Code I installed the Azure Tools for Visual Studio Code. To install this extension:
– Open the extension view (CTRL-Shift-X) and type “Azure Tools”.
– Click on the green Install button
– activate the extension

In order to use the Azure: Login command go to File, Preferences, Settings and type the following between the curly brackets:
"azure.tenantId": "<your Azure tenant ID"

To retrieve your tenant ID login to the ARM portal and select the Azure Active Directory. Select App registrations and click on Endpoints. Copy the URL of the federation metadata document and strip out the first and last part so you end up with your tenant ID.
It looks like 12345678-abcd-1a23-a12b-1a2bc3defa4b

To logon do CTRL-P and type >azure. If al goes well you should see the following commands to choose from.

The first command you should use is Azure: Login. This will give you a code to fill in during the logon process similar like the Azure CLI logon process.

But you don’t have to do it from Visual Studio Code. You could also write your JSON template file, save it, and use it with powershell i.e. 

New-AzureRmResourceGroupDeployment -Name "MyDeployment" -ResourceGroupName "MyResourceGroup" -TemplateFile "MySavedJSONFile"