HybridCloud.social

Share This Post

Monitoring / SCOM

Backing Up SCOM Custom Management Packs Automatically With Folder Structure

Originally posted by Connor McCardle

I was asked by a customer to create a simple automated backup method to ensure their custom SCOM management packs were backed up, but also whilst keeping a sensible folder structure. This ended up being a simple PowerShell script which was ran on a schedule using Task Scheduler on one of the management servers.

One of the requests was to give a folder structure like this: \<date>\<management pack name>\<management pack version>\.

The following PowerShell script is what we used to achieve this:

####

Import-Module OperationsManager

Get-ChildItem “E:\Management Packs\Backups\Overrides” |? {$_.psiscontainer -and $_.lastwritetime -le (get-date).adddays(-7)} |% {remove-item $_ -force -Recurse}

$date = date -Format dd-MM-yyyy

$csv = “E:\Management Packs\Backups\OverridesList.csv”

Get-SCOMManagementPack | ?{$_.displayname -like “*.Overrides*”} | Export-CSV -Path $csv -Force

$list = Import-CSV -Path $csv

foreach ($item in $list)

{
$foldername = $item.DisplayName
$folderversion = $item.Version

If (!(Test-Path “E:\Management Packs\Backups\Overrides\$date\$foldername”)) {

New-Item -Path “E:\Management Packs\Backups\Overrides\$date\$foldername” -ItemType Directory
}
}

foreach ($item in $list)

{
$foldername = $item.DisplayName
$folderversion = $item.Version

If (!(Test-Path “E:\Management Packs\Backups\Overrides\$date\$foldername\$folderversion”)) {

New-Item -Path “E:\Management Packs\Backups\Overrides\$date\$foldername\$folderversion” -ItemType Directory
}
}

foreach ($item in $list)
{
$foldername = $item.DisplayName
$folderversion = $item.Version
$mpid = $item.Id

Get-SCOMManagementPack -Id $mpid | Export-SCOMManagementPack -Path “E:\Management Packs\Backups\Overrides\$date\$foldername\$folderversion”

}

####

There were some simpler versions of this, such as just creating folders for name and version, but these can be acheived by removing code from the above script.

Share This Post

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">

Lost Password

Register