OpsMgr / SCOM 2012 MP Backup PowerShell Script

Recently I came across a post that someone in the Operations Manger Community had posted about the new SCOM 2012 PowerShell command that allows you to export all your Management Packs to XML files.

Get-SCManagementPack | Export-SCManagementPack -path C:\MPDUMP

This was great starting place for creating a PowerShell Script that could run a daily scheduled task to backup all SCOM  Management Packs.
Below is the “quick and dirty” script that i wrote to get this started. It still needs some refinements but for the majority of the year it will do what i need it to.

# Filename:      MP_Daily_Backup.ps1
# Description:   This Script exports all Management Packs on a daily schedule.
# Directory Structure: YYYYDDMMM – will remove directories that are exact day 1 month earlier.
#
Import-Module OperationsManager
d:\’Program Files’\’System Center 2012’\’Operations Manager’\Powershell\OperationsManager\Functions.ps1
d:\’Program Files’\’System Center 2012’\’Operations Manager’\Powershell\OperationsManager\startup.ps1
$Date = get-date -uformat “%Y%d%m”
mkdir d:\MPBackup\$Date
Get-SCManagementPack | Export-SCManagementPack -path d:\MPBackup\$Date
$LastMonth = $Date – 1
Remove-Item d:\MPBackup\$LastMonth -force -recurse

This script will export all Management Packs in XML format to the D:\MPBackup\$Date (Where $Data = today’s date in YearDayMonth format.)

The issue with this script is that it will not remove old directories for December and in in January it will not get the 3 or 4 days (depending on leap year).  I will be working on refining this script but I wanted to be sure to share.

Disclaimer: I am happy to share so feel free to use this code, but do so at your own risk. I am not responsible if it breaks something.

Good luck!

Advertisements

~ by Josh on September 12, 2012.

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

 
%d bloggers like this: