Clean All Obsolete MP References From Your SCOM Management Group

File this under, “good to do now and then”.
This example script snippet below will do the following:

  • Export all unsealed MPs (.XML files)
  • Remove obsolete alias references from the MPs, saving modified copies to a separate folder
  • Import the modified MPs (.XML files) back into SCOM

When I set out to write this article, I did what I do almost every time I try to use a function from the SCOMHelper PowerShell module; I list all of the commands within the module like this:
Note: I use Powershell ISE most of the time.

Get-Command -Module SCOMHelper

Then I put my cursor on the desired command name and press F1 which opens the Help documentation (PowerShell ISE)

Once I have the Help window open I can look at the examples that I wrote so long ago to speed up my next scripting attempt. Alternatively, you can use the following command to view Help documentation for any command:

Get-Help 'Remove-SCOMObsoleteReferenceFromMPFile' -Full

Now, to the good part! Here’s the snippet to do the work:

Clean all obsolete references from unsealed MPs
Author: Tyson Paul

# Create a unique root folder to store exported MP files
$TimeStamp = Get-Date -Format 'yyyyMMdd-HHmmss'
$ExportedMPFolder = "C:\Temp\MPExport\Exported_$($TimeStamp)"
New-Item -Path $ExportedMPFolder -ItemType Directory

# This is where the modified files will be stored
$ModifiedMPFolder = "C:\Temp\MPExport\Modified_$($TimeStamp)"

# Export all unsealed MPs
Get-SCOMManagementPack | Where-Object {$_.Sealed -eq $False} | Export-SCOMManagementPack -Path $ExportedMPFolder -Verbose

# Output modified versions. The original MP files will not be modified.
Remove-SCOMObsoleteReferenceFromMPFile -inFile "$ExportedMPFolder\*.xml" -outDir $ModifiedMPFolder

# Import all modified/cleaned MP files
Get-ChildItem -Path $ModifiedMPFolder | ForEach-Object {Import-SCOMManagementPack -Fullname $_.FullName -Verbose}

Original unsealed MPs get exported to the designated folder:

Obsolete references get cleaned out, modified files get saved in the output folder:

Cleaned files get reimported:


Leave a Reply

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