Backup and Restore ConfigMgr Site Maintenance Task Settings with PowerShell

According to the official Microsoft documentation, when upgrading to System Center Configuration Manager (current branch), it is recommended to disable any site maintenance tasks that could run during the upgrade (as they can cause the upgrade to fail), and to make a record of the task schedules for any disabled tasks:

Before you disable a task, record the schedule of the task so you can restore its configuration after the site upgrade completes.

Since I don’t want to manually note down the schedules for my maintenance tasks, I wrote a couple of PowerShell scripts to backup and restore the site maintenance task settings for me.

The backup script will export the settings for each site maintenance task and save them to file in json format.

The restore script will then read each backup file, compare the current settings in WMI with the backed-up settings for each maintenance task, and update anything that doesn’t match. The script will tell you if anything has changed and what the old and new values are.

If you run the backup before you disable the tasks, the restore script will re-enable them again.

Both scripts should be run elevated on your primary site server.

Backup-CMSiteMaintenanceTaskSettings

To backup, simply pass the sitecode and the backup directory to the script:


Backup-CMSiteMaintenanceTaskSettings -SiteCode ABC -BackupDirectory G:\Backup\SiteMaintenanceTasks

You will then see a json file for each site maintenance task in the backup directory:

jsonfiles

Restore-CMSiteMaintenanceTaskSettings

To restore, pass the same parameters to the script:


Restore-CMSiteMaintenanceTaskSettings -SiteCode ABC -BackupDirectory G:\Backup\SiteMaintenanceTasks

The script will read each file then compare the settings with the current task settings in WMI. If there are any differences, these will be updated and reported:

restore

Scripts

Advertisements

5 thoughts on “Backup and Restore ConfigMgr Site Maintenance Task Settings with PowerShell

  1. Hi, I’ve just tried your scripts (awesome idea by the way), the backup part seems to work great, but whenever I try to restore, it gives me the following error for each setting/task
    The property ‘xx’ cannot be found on this object. Verify that the property exists and can be set.

    Do you know why that would be?

    I’ve looked at your jason files and the data seems to have been backed up properly.

    Thks in advance and don’t hesitate if you have any questions.

    Steph

  2. Hello it’s the command ConvertFrom-Json that gives the following error :
    ConvertFrom-Json : Invalid object passed in, ‘:’ or ‘}’ expected. (1): {
    At line:34 char:62
    + $JSON = Get-Content -Path $File -ErrorAction Stop | ConvertFrom-Json -E …
    + ~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : NotSpecified: (:) [ConvertFrom-Json], ArgumentException
    + FullyQualifiedErrorId : System.ArgumentException,Microsoft.PowerShell.Commands.ConvertFromJsonCommand

  3. Never mind, I just inserted : |out-string| and it works.
    Original command line(35) : $JSON = Get-Content -Path $File -ErrorAction Stop | ConvertFrom-Json -ErrorAction Stop
    New command line (working) : $JSON = Get-Content -Path $File | Out-String | ConvertFrom-Json -ErrorAction Stop

    Thank you.

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s