Last post, I wrote about retrieving management packs from Service Manager and I don't really have a lot more to say about retrieving the management pack information, except for provide a way where we don't have to specify formatting. Generally, I want to see whether the management pack is sealed, the version number and then name, which translates into using format-table like this:
format-table Sealed,Version,Name -autosize
I'll create a ServiceManager.Format.ps1xml file which will format the default view of management packs.
<configuration>
In order to add this to my environment, all I need to do is use the Update-FormatData cmdlet using the filename as an argument. After that, retrieving management packs will be be in the format that I want.
So less typing for me, yay!
For even less typing, I'll create a script called Get-ManagementPack which creates a connection to Service Manager and retrieves the management packs.
here's the script:
and to run:
Now we have a simple script and default formatting. But we're not done with management packs - if I want to see the contents of a management pack, I can do that via a process called " exporting ". Exporting a management pack lets me create an XML file of the management pack which I can then inspect the various elements of the management pack so I can see what it does (and how it does it). An object exists for just the purpose of exporting management packs - Microsoft.EnterpriseManagement.Configuration.IO.ManagementPackXmlWriter and using the WriteManagementPack method, I can easily create the XML files.
This is perfect for a foreach pipeline, so for each management pack that I retrieve, I'll create an XML file of the management pack contents.
The first script block in the foreach command creates me an xmlWriter which will used for all the management pack objects that are passed from Get-ManagementPack. The ManagementPackXmlWriter object has two constructors. The constructor that I'm using takes a string which points to a directory which will contain the exported xml files. When invoked, the method returns a string which is the fullname of the exported XML file, so when I execute it, I see the following (ellipses used to save space):
I can easily incorporate this into a script as well:
I've also added support for -verbose so I can see what's being exported if I want, along with just a little checking to be sure that I've actually got a management pack.
Now I can run the following:
and export all my management packs in one simple step. Next time I'll discuss importing management packs.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.