Monday, 13 February 2012

Backup unsealed management packs in Service Manager - Update needed

Thanks to Sam for pointing out that my previous MP & Powershell combo for backing up unsealed management packs had stopped working when he tried to implement it the other day.

Something must have changed with the Powershell cmdlets, but anyway, I've found out what needs changing.

Using the latest SMLets from here:

I've highlighted the changes in the powershell script (and also checked this against a 2012 install):

#Initializing the SCSM 2010/2012 Powershell Snapin
Import-Module SMLets -ErrorVariable errSnapin ;

#Remove old backups
$xDays = (Get-Date).addDays($DeleteDate)
Get-ChildItem $targetFilePath -Recurse | where {$_.lastWriteTime -le $xDays} | Remove-Item -recurse -force
#Create TargetDir if it doesn't exist
if (test-path $targetFilePath)
"Folder Exists"
md "$targetFilePath"
#Create new backup dir
md "$targetFilePath\MP_$((get-date).toString('yyyyMMdd'))"
#Backup unsealed MP's
Get-SCSMManagementPack|where-object {! $_.Sealed}|Export-SCSMManagementPack -TargetDirectory "$targetFilePath\MP_$((get-date).toString('yyyyMMdd'))"

I'll try and get an updated bundle uploaded to the TechNet Gallery soon.

No comments: