Last month, in TechEd North America, Cameron Fuller demonstrated a PowerShell script to search and remove obsolete MP references from an unsealed management pack. The script was written by Cameron’s colleague Matthew Dowst. You can watch Cameron’s presentation here and get the script here.
After TechEd, Cameron emailed me and suggest me to add this script into my OpsMgr Self Maintenance management pack. So before I built this functionality into the Self Maintenance MP, I have written a similar stand-alone script as a proof-of-concept.
The differences between my version and Matthew Dowst version are:
- No need to export and re-import unsealed management packs: My script directly reads and updates MP contents using SCOM SDK. therefore unsealed MPs don’t need to be exported and re-imported.
- Scan through all unsealed MPs: My script go through all unsealed MPs rather than individual XML files.
- Option to backup MPs before changes are made: the script accept parameters to backup original unsealed MPs before any changes are made.
- Option to increase MP version or keep version the same: Users can choose whether the MP version should be increased.
- Allow test run (-WhatIf): Users can use –WhatIf switch to test run the script before changes are made.
- MP Verify: the script verifies the MP before and after changes. if MP verify fails (including pre-existing errors), no changes will be made to the particular MP.
- Allow Users to customize a “white list” for common MPs: When obsolete references are detected for the “common management packs” defined in the CommonMPs.XML (placed in the same folder as the script), these references will be ignored. This is because these common management packs are referenced in many out-of-box unsealed management packs by default. Additionally, since it is very unlikely these management packs will ever be deleted from the management group, therefore it should not be an issue when they are referenced in other management packs. Users can manually add / remove MPs from the list by editing the CommonMPs.XML. I have pre-populated the white list and included the following MPs:
You can run this script on any computers have OpsMgr 2012 console /agent / management server installed. The script includes a help documentation. you can access it via:
get-help .\MPReferencesCleanUp.ps1 –full
#1. Test run using -WhatIf: .\MPReferencesCleanUp.ps1 -ManagementServer “OPSMGRMS01” –BackupBeforeModify –BackupLocation “C:\Temp” -IncrementVersion –WhatIf
#2. Real run without –WhatIf: .\MPReferencesCleanUp.ps1 -ManagementServer “OPSMGRMS01” –BackupBeforeModify –BackupLocation “C:\Temp” –IncrementVersion
The script can be downloaded HERE.
As I mentioned in the beginning, the next version of the OpsMgr 2012 Self Maintenance MP will have the ability to detect and remove these obsolete references. The MP is pretty much done. I’ve sent it to few people to test. I should be able to publish it in few days. Despite the new functionalities of the self maintenance MP, this script will still be a good standalone tool to run ad-hoc when needed.
I’d like to thank the following people for testing and advices provided to this script (in random order):
- Cameron Fuller
- Raphael Burri
- Marnix Wolf
- Bob Cornelissen
- Dan Kregor
I also want to thank Matthew Dowst for the original script and Matthew Long for his blog post where I got the ideas from.
Lastly, as always, please feel free to contact me if you have questions / issues.