Created
April 6, 2017 10:56
Star
You must be signed in to star a gist
Backs up ConfigMgr Site Maintenance Task settings from WMI to json files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## Saves ConfigMgr Site Maintenance Task settings from WMI to json files ## | |
## Should be run on the Primary Site Server ## | |
## Should be run as administrator ## | |
[cmdletbinding()] | |
Param( | |
[Parameter(Position=0,Mandatory=$True)] | |
[ValidateNotNullorEmpty()] | |
[string]$SiteCode, | |
[Parameter(Position=1,Mandatory=$True)] | |
[ValidateNotNullorEmpty()] | |
[string]$BackupDirectory | |
) | |
Try | |
{ | |
# Load maintenance tasks from WMI | |
$MTs = Get-WmiObject -Namespace ROOT\SMS\site_$SiteCode -Class SMS_SCI_SQLTask -ErrorAction Stop | |
} | |
Catch | |
{ | |
$_ | |
Return | |
} | |
If ($MTs) | |
{ | |
# Iterate through each task, convert to hash table, output to json format, save to file | |
$MTs | foreach { | |
# Convert to hash table | |
$Values = @{} | |
$_.Properties | Foreach { | |
$Values.Add($_.Name, $_.Value) | |
} | |
Try | |
{ | |
# Convert to json format, save to file | |
$Values | ConvertTo-Json -ErrorAction Stop | Out-File "$BackupDirectory\$($_.TaskName).json" -ErrorAction Stop -Force | |
} | |
Catch | |
{ | |
$_ | |
} | |
} | |
} | |
Else | |
{ | |
Write-Warning "No maintenance tasks found!" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment