MP Authoring Helper
This week I’m having an internal MP Authoring Workshop from Brian Wren and I learned that it’s sometimes handy to have information available that’s not available when having the MP Authoring tool open. You can not switch to the Service Model when you have an other windows open.
That’s why I created a PowerShell script that let’s you easily have a look at all the Classes, Discoveries, Relationships and Modules you already created in your Management Pack (if you have saved it).
Just copy the script and save it to “MPAuthoringHelper_v1.003.ps1”
############################################################################### # Getting Classes from MP XML file and exporting it to csv for use in the # MP Authoring tool # Authors: Stefan Stranger # v1.001 - 27/01/2010 - sstranger - initial sstranger's release # v1.002 - 11/03/2010 - sstranger - added GetRelationshipTypes Function and changed GetClasTypes Function # - added GetDiscoveries Function # v1.003 - 11/03/2010 - sstranger - added GetModules Function ############################################################################### param ([string]$Path = $(read-host "Please enter MP XML path and file name")) #Globals $global:XmlMPFileDocument = new-object System.Xml.XmlDocument # Get MP XML file. # Make sure you saved your MP file to XML regularly. $XmlMPFileDocument.Load($Path) ############################################################################################## #Function GetClassTypes # #Get Class Types from MP XML file ############################################################################################# Function GetClassTypes { $MyClassTypes = $XmlMPFileDocument.ManagementPack.TypeDefinitions.EntityTypes.ClassTypes.ClassType $MyClassTypes | select @{n='Class Name';e='ID'},@{n='Base Class';e='Base'}, Abstract, Singleton } ############################################################################################## #Function GetRelationshipTypes # #Get RelationShip Types from MP XML file ############################################################################################# Function GetRelationshipTypes { $myRelationshipTypes = $XmlMPFileDocument.ManagementPack.TypeDefinitions.EntityTypes.RelationshipTypes.RelationshipType $myRelationshipTypes | select @{n='Name';e='ID'},@{n='Base Class';e='Base'}, Abstract, Source, Target } ############################################################################################## #Function GetDiscoveries # #Get Discoveries from MP XML file ############################################################################################# Function GetDiscoveries { $myDiscoveries = @() foreach ($Discovery in $XmlMPFileDocument.ManagementPack.Monitoring.Discoveries.Discovery) { $obj = new-object System.Management.Automation.PSObject $obj = $obj | add-member -membertype NoteProperty -name "Name" -value $Discovery.ID -passthru $obj = $obj | add-member -membertype NoteProperty -name "Target" -value $Discovery.Target -passthru $obj = $obj | add-member -membertype NoteProperty -name "Discovery Class" -value $Discovery.DiscoveryTypes.DiscoveryClass.TypeID -passthru $obj = $obj | add-member -membertype NoteProperty -name "DS TypeID" -value $Discovery.DataSource.TypeID -passthru $myDiscoveries = $myDiscoveries + $obj } $myDiscoveries } ############################################################################################## #Function GetModules # #Get Modules from MP XML file ############################################################################################# Function GetModules { $myModules = @() if ($XmlMPFileDocument.ManagementPack.TypeDefinitions.ModuleTypes.ProbeActionModuleType) { foreach ($ProbeModule in $XmlMPFileDocument.ManagementPack.TypeDefinitions.ModuleTypes.ProbeActionModuleType) { $obj = new-object System.Management.Automation.PSObject $obj = $obj | add-member -membertype NoteProperty -name "Module Type" -value "Probe" -passthru $obj = $obj | add-member -membertype NoteProperty -name "Name" -value $ProbeModule.ID -passthru $obj = $obj | add-member -membertype NoteProperty -name "Type ID" -value $ProbeModule.ModuleImplementation.Composite.MemberModules.ProbeAction.TypeID -passthru $myModules = $myModules + $obj } } if ($XmlMPFileDocument.ManagementPack.TypeDefinitions.ModuleTypes.DataSourceModuleType) { foreach ($DSModule in $XmlMPFileDocument.ManagementPack.TypeDefinitions.ModuleTypes.DataSourceModuleType) { $obj = new-object System.Management.Automation.PSObject $obj = $obj | add-member -membertype NoteProperty -name "Module Type" -value "Data Source" -passthru $obj = $obj | add-member -membertype NoteProperty -name "Name" -value $DSModule.ID -passthru $obj = $obj | add-member -membertype NoteProperty -name "Type ID" -value $DSModule.ModuleImplementation.Composite.MemberModules.DataSource.TypeID -passthru $myModules = $myModules + $obj } } if ($XmlMPFileDocument.ManagementPack.TypeDefinitions.ModuleTypes.WriteActionModuleType) { foreach ($WAModule in $XmlMPFileDocument.ManagementPack.TypeDefinitions.ModuleTypes.WriteActionModuleType) { $obj = new-object System.Management.Automation.PSObject $obj = $obj | add-member -membertype NoteProperty -name "Module Type" -value "Write Action" -passthru $obj = $obj | add-member -membertype NoteProperty -name "Name" -value $WAModule.ID -passthru $obj = $obj | add-member -membertype NoteProperty -name "Type ID" -value $WAModule.ModuleImplementation.Composite.MemberModules.WriteAction.TypeID -passthru $myModules = $myModules + $obj } } if ($XmlMPFileDocument.ManagementPack.TypeDefinitions.ModuleTypes.ConditionDetectionModuleType) { foreach ($ConditionModule in $XmlMPFileDocument.ManagementPack.TypeDefinitions.ModuleTypes.ConditionDetectionModuleType) { $obj = new-object System.Management.Automation.PSObject $obj = $obj | add-member -membertype NoteProperty -name "Module Type" -value "Condition Dectection" -passthru $obj = $obj | add-member -membertype NoteProperty -name "Name" -value $ConditionModule.ID -passthru $obj = $obj | add-member -membertype NoteProperty -name "Type ID" -value "See XML for more info" -passthru $myModules = $myModules + $obj } } $myModules } #Call Functions GetClassTypes | Out-GridView GetRelationshipTypes | Out-GridView GetDiscoveries | Out-GridView GetModules | Out-GridView |
It only needs one parameter and that’s the path and filename of the MP xml file you are creating. Remember to save your MP xml file regularly.
Have fun creating new MP’s!
Comments
Anonymous
January 01, 2003
That's pretty neat, Stefan. Be aware that you have the path hard-coded. I needed to comment that out. Also FYI - When I run this, four windows pop open.Anonymous
January 01, 2003
Hi Jonathan, Thanks for telling me about the hard-coded paths. Used them for testing ;-) Removed those. And it's correct that four Windows Open at the same time. If you don't want that just REM the not wanted functions, like this: #GetRelationshipTypes | Out-GridView Or you can add parameters to select what you want to see. Regards, Stefan