17 juil. 2011

Export the pinpoint MP's catalog into a single html page

If, in your company, people asks you all the time is there any management pack for monitoring this or this application and you give them all the time the link to the pinpoint catalog  (where you can find all provided MP by Microsoft or third party) but never take the time to click or search, than you are like me.... :)


You might need to publish this list on your sharepoint server (or any web server) or just send this list by mail.


That's why I have created this script to export the catalog in an HTML document to be shared in my organization.


The following script parse the pinpoint catalog and retreive the information in order to be exported in a simple HTML document.


Source script: here

###################################################################################
# Parsing and exporting the pinpoint systemcenter catalog to get it in one page #
# The purpose is to be able to distrib this catalog inside company's organization #
# #
# Author: Laurent De Berti #
# v1.0 - 17/7/2011 #
###################################################################################

# We need 2 Internet Explorer
# 1st one is to retreive the list of all MPs
# 2nd one is to retreive the description for each MP

$oIE=new-object -com internetexplorer.application
$oie2=new-object -com internetexplorer.application

#$count is the 1st page
$count = 1

$res=5
$baseurl="http://systemcenter.pinpoint.microsoft.com"
$mp=@()

# Looping for each page of Management Packs
while ($res -ne 1) {
"Page $count"

# Let's retreive all the page
$oIE.navigate($baseurl + "/en-US/applications/search/operations-manager-d11/management-packs-b200073?page="+$count+ "&sort=released&q=")

while ($oIE.busy) {
    sleep -milliseconds 250
}

# By using the HTML dl tag, we check how many MPs are return.

$res=0; $oIE.document.getElementsByTagName("dl") | % { $res+=1 }
$oIE.document.getElementsByTagName("dl") | % { 
$HTMLPart= $_.IHTMLElement_innerHTML
$title = $HTMLPart| select-string -Pattern 'title="(?<hid>[ 0-9a-zA-Z-]+)'| select -expand Matches | foreach {$_.groups["hid"].value}

# if title is set as "Best Match", we skip this line 'headline of the table
if ($title -ne "Best Match") { 

# start recording and parsing the web page for each MP
$record  = New-Object system.Object
$record | add-Member -memberType noteProperty -name ManagementPackName -Value $title
"Adding " + $title
#$record | add-Member -memberType noteProperty -name Description -Value ($HTMLPart| select-string -Pattern '<DD class=description><SPAN>(?<hid>[ 0-9a-zA-Z-:,.®]+)...'| select -expand Matches | foreach {$_.groups["hid"].value})
$record | add-Member -memberType noteProperty -name Company -Value ($HTMLPart| select-string -Pattern '<SPAN>Plug-in by: <SPAN class="fn org">(?<hid>[ 0-9a-zA-Z-:,.®]+)</SPAN>'| select -expand Matches | foreach {$_.groups["hid"].value})
$record | add-Member -memberType noteProperty -name ReleaseDate -Value ($HTMLPart| select-string -Pattern '<B>Release Date: </B>(?<hid>[ 0-9a-zA-Z-:,.®/]+) </DD>'| select -expand Matches | foreach {$_.groups["hid"].value})
$record | add-Member -memberType noteProperty -name Ver -Value ($HTMLPart| select-string -Pattern '<B>Version: </B>(?<hid>[ 0-9a-zA-Z-:,.®]+) </DD>'| select -expand Matches | foreach {$_.groups["hid"]value})
$downloadlink= $baseurl + ($HTMLPart | select-string -Pattern '="Application Details" href="(?<hid>[ 0-9a-zA-Z-:,./]+)"'| select -expand Matches | foreach {$_.groups["hid"].value})
$record | add-Member -memberType noteProperty -name DownloadLink -Value $downloadlink


# opening another IE to get the description from the link page
$oie2.navigate($downloadlink)
while ($oie2.busy) {
          sleep -milliseconds 250
}
$desc=($oie2.document.getElementsByTagName("p") | ? {$_.classname -eq "appDetailDescription"}).IHTMLElement_outerText

$record | add-Member -memberType noteProperty -name Description -Value $desc

# Adding the record to the new mp system.object
$mp+=$record
}
}


# Let's go the next page.
$count++

}

# $mp contains all the MP
# printing out the result
$mp

# exporting in HTML to get the catalog.
$head = '<style> BODY{font-family:Trebuchet; background-color:white;} H1{font-size:1.3em;} TABLE{border-width: 1px;border-style: solid;border-color: black;border-collapse: collapse;} TH{font-size:0.8em; border-width: 1px;padding: 2px;border-style: solid;border-color: black;background-color:#CEE3FF} TD{font-size:0.8em;border-width: 1px;padding: 2px;border-style: solid;border-color: black;background-color:#F7FFE8} </style>'

$mp | ConvertTo-HTML  -body "<P><H1>Here the full list of management pack in the pinpoint catalog</H1><P>" -head $head -title "pinpoint - list of managementpack"| out-file c:\mp.html

Aucun commentaire: