The following script was something I put together recently as a time saver.

On reddit someone on the SCOM channel asked how to pull specifically PowerShell script from a management pack. If you have a sealed mp file first it will need to be extracted to an xml file. To do this we will use the power of MP Viewer a utility that I use almost every day.MP Viewer can be downloaded from Microsoft TechNet Gallery.
Please note the SCOM Console will need to be installed on the system you plan on running MP Viewer from. On that system fire up MP Viewer and open and MP File. once it has finished loading the mp file, click File –> Unseal/Unpack Management Pack option, select the destination where the file will go, I usually keep the default name of the xml file and put it in the same folder where the MP file is found.The easiest way to get all the scripts from the xml file would naturally be to run the PowerShell script which is saved to my C:\Temp3\scriptsfrommps.ps1 below:Line one sets the XML file that is read into memory, lines two and three query for ScriptName and ScriptBody in the xml file and assign them to variables. Line four is a for loop which will go thru each ScriptName until they have all been used. inside the loop the currnet Script Name and Script body is written to a file in the current directory.

PowerShell
Edit|Remove
[xml] $SQLMP = Get-Content -Path C:\temp3\Microsoft.SQLServer.2012.Monitoring.xml 
 
$ScriptName = $SQLMP.SelectNodes("//ScriptName")."#text" 
$ScriptBody = $SQLMP.SelectNodes("//ScriptBody")."#text" 
 
for ($i=0; $i -lt $SQLMP.SelectNodes("//ScriptName").count; $i++) 
 
{ 
 $ScriptBody[$i] >> $ScriptName[$i] 
}
 


Now my C:\Temp3 folder will be littered with the scripts from the SQL Server 2012 Monitoring MP, all scripts in that MP which will be everything from vb script to java to PowerShell. Change the first line to which ever management pack xml file that you would like to inspect the scripts from.