Friday, March 8, 2013

[OpsMgr 2007 R2][OpsMgr 2012] Powershell script to list all references stored in all unsealed Management Pack

I'm actually doing some clean up in our 2007 R2 environment to be sure that all management pack are OK before importing them in our new SCOM 2012  environment.



As you know, best practices is to create one override MP by MP you want to tune. One of the tasks we wanted to do is to ensure that all overrides stored in unsealed MPs are corresponding to the sealed assocaited MP.

Listing all references of unsealed MPs is a good help to identify what unsealed MP has a reference on a MP (and also override) that should not be referenced !

Download the file :

Or create a file : ListReferenceUnsealedMPs.ps1

  1. param([string]$Path)
  2. $Exportfile = [string]$Path + "\ListAllReferencesForNonSealedMPs.csv"
  3. $Exportfile
  4. # SCOM 2007R2
  5. $mps = get-managementpack | where-object {$_.Sealed -eq $false}
  6. # SCOM 2012
  7. # $mps = Get-SCOMManagementPack | where-object {$_.Sealed -eq $false}
  8. "Management Pack Name;Reference Name;Reference Key Token;Reference Version;Reference ID;Reference Version ID" >> $Exportfile
  9. Foreach ($mp in $mps)
  10.  {
  11.  $References = $mp.References
  12.  foreach ($Ref in $References)
  13.   {
  14.   $mp.Name + ";" + $Ref.name + ";" + $Ref.KeyToken + ";" + $Ref.Version  + ";" + $Ref.Id + ";" + $Ref.VersionId >> $Exportfile
  15.   }
  16.  }
 Then you can use the ListReferenceUnsealedMPs.ps1 "C:\temp" command line in a powershell connected to your SCOM (don't forget to comment line 5 + un-comment line 7 for using in 2012).

This will create a c:\Temp\ListAllReferencesForNonSealedMPs.csv that contains all References by unsealed MP.

Openning the .csv file with excel will give you :


 Enjoy !

This posting is provided "AS IS" with no warranties.

No comments:

Post a Comment