Skip to content

Instantly share code, notes, and snippets.

  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save SMSAgentSoftware/5161324e136b4f0427565c62fa06602d to your computer and use it in GitHub Desktop.
Backs up ConfigMgr Site Maintenance Task settings from WMI to json files
## 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