Date: Sun, 19 May 2013 05:58:29 +0200
Quote:
- Time is an illusion. Lunchtime doubly so.
Testing the Integrity of a Management Pack
http://jtruher3.wordpress.com/2010/05/12/testing-the-integrity-of-a-management-pack/
Text:
When I’m creating a new management pack, I want to be sure that the management pack is valid before I import it. I know that if it’s wrong, the system won’t import it, but I generally like to know these things before I try. In order to do that, I wrote a pretty simple script to test the management pack. It takes advantage of the Verify method on management pack object. This verification does a number of things. First, it checks to be sure that there are no XSD validation errors. If there are, the method throws an exception. The Verify method also checks to be sure that references are correct and present. Note that there may still be some errors that are found upon import, but most of the issues will be caught by this script.
When everything works right, you’ll see something like the following:
PS> test-managementpack .\PowerShell.WATest.xml|ft Verified,Name,FullName -au Verified Name FullName -------- ---- -------- True PowerShell.WATest C:\Program Files\System Center Management Packs\PowerShell.WATest.xml
However, if something is busted, you'll see this:
PS> test-managementpack .\BigHonkingMP.xml|Ft Verified,Name,FullName -au Verified Name FullName -------- ---- -------- False BigHonkingMP C:\Program Files\System Center Management Packs\BigHonkingMP.xml
The results of test-managementpack include the error, you can see what happened, by getting the Error property:
PS> test-managementpack .\BigHonkingMP.xml|Fl name,error
Name : BigHonkingMP
Error : {Exception calling "Verify" with "0" argument(s): "Verification failed with 1 errors:
-------------------------------------------------------
Error 1:
: Failed to verify class: BigHonkingMP.ConcreteMicroBleh
Host class BigHonkingMP.AbstractBleh and hosted class BigHonkingMP.ConcreteMicroBleh define the same set of key properties.
-------------------------------------------------------
"}
You can also pipe files at test-managementpack, so you can use it like this:
PS> ls *.xml|test-managementpack Verified Name FullName -------- ---- -------- False BigHonkingMP C:\Program Files\System Center Management Packs\BigHonkingMP.xml . . .
Which I thought was pretty handy - going through a bunch of MPs at once.
Here's the script, it relies on version 2.0 of PowerShell. I've added online help, so you can run get-help test-managementpack to get info on it. The business end of the script is in line 29 and 30. That's where I create a management pack object and then call verify. If the management pack object can't be created, or if it fails verify, the exception gets caught and then the script builds up an error message. Rather than using Write-Error to indicate the problem, I decided to include the error message in resultant object. I did this because I didn't really want the error output at this point, but I wanted to hang on to the verify failure.
|
001
002 003 004 005 006 007 008 009 010 011 012 013 014 015 016 017 018 019 020 021 022 023 024 025 026 027 028 029 030 031 032 033 034 035 036 037 038 039 040 041 042 043 044 045 046 047 048 049 050 051 052 053 054 055 056 057 058 059 060 061 062 063 064 065 066 067 068 069 070 071 072 073 074 075 076 077 078 079 080 081 082 083 084 085 086 087 088 089 090 |
#requires -version 2.0
param ( BEGIN PROCESS <# .INPUTS #> |
Via FeedShow.com