Deployment

Nice to Know – Dumping MDT Monitor data to a Webpage (using PowerShell)

(update – https://deploymentbunny.com/2013/12/13/nice-to-know-dumping-mdt-monitor-data-to-a-webpage-using-powershell-update/)

A customer asked me –Could you create like a web page that shows the same info as the MDT monitoring tab, so can see all the deployment all the time?, the answer is of course –Yes, of course you can!

Now, before you start barking at me and say “That could be done much easier using C#, Lisp, VB.Net” or something, this was the “My-flight-leaves-very-soon” kind of coding, so it jus a very simple PowerShell snip that runs on a 5 min schedule and create a new page and the result looks like this:

image

The script will read the data from the MDT monitoring feed, so the web server does not need to be on the server it self, it does not require anything at all, the script generates a HTML page and the we “modify” it on the fly and the save it in the inetpub folder, and here is the code:

image

And in text form:

$URL = "http://EDUDEPLOY09:9801/MDTMonitorData/Computers"

function GetMDTData { 
  $Data = Invoke-RestMethod $URL

  foreach($property in ($Data.content.properties) ) { 
    New-Object PSObject -Property @{ 
      Name = $($property.Name); 
      PercentComplete = $($property.PercentComplete.’#text’); 
      Warnings = $($property.Warnings.’#text’); 
      Errors = $($property.Errors.’#text’); 
      DeploymentStatus = $( 
        Switch ($property.DeploymentStatus.’#text’) { 
        1 { "Active/Running" } 
        2 { "Failed" } 
        3 { "Successfully completed" } 
        Default { "Unknown" } 
        } 
      ); 
      StartTime = $($property.StartTime.’#text’) -replace "T"," "; 
      EndTime = $($property.EndTime.’#text’) -replace "T"," "; 
    } 
  } 
} 

$Head = "<style>"
$Head = $Head + "BODY{background-color:peachpuff;}"
$Head = $Head + "TABLE{border-width: 2px;border-style: solid;border-color: black;border-collapse: collapse;}"
$Head = $Head + "TH{border-width: 1px;padding: 0px;border-style: solid;border-color: black;background-color:thistle}"
$Head = $Head + "TD{border-width: 1px;padding: 0px;border-style: solid;border-color: black}"
$Head = $Head + "</style>"

$Title = "LabCenter Deployment Status"

GetMDTData | Select Name, DeploymentStatus, PercentComplete, Warnings, Errors, StartTime, EndTime | Sort -Property Name |
ConvertTo-Html  `
-Title $Title  `
-Head $Head  `
-Body (Get-Date -UFormat "%Y-%m-%d - %T ")  `
-PreContent "<H2>LabCenter Deployment Status for: $ENV:COMPUTERNAME </H2><P>Generated by Power of the Force</P>"  `
-PostContent "<P>For details, contact support@truesec.se.</P>"  `
-Property Name,DeploymentStatus,PercentComplete,Warnings,Errors,StartTime |
ForEach {
if($_ -like "*<td>Successfully completed</td>*"){$_ -replace "<tr>", "<tr bgcolor=green>"}
elseif($_ -like "*<td>Failed</td>*"){$_ -replace "<tr>", "<tr bgcolor=red>"}
else{$_}
} > C:\inetpub\wwwroot\default.htm 
#Invoke-Item $ENV:TEMP\Default.htm

And as a download of course http://sdrv.ms/J4ttVC

/mike

Categories: Deployment, MDT, PowerShell, SCCM

Tagged as: , ,

28 replies »

  1. Hi Mike, anyone,
    Can we have a step by step by step guide on where to put the ps1 file, how to configure IIS and how to view the webpage.
    Many thanks,

    • Hi, sorry. The only thing you need to do is to download the POSH script, edit the URL so it points to your MDT server. When that is done, execute the powershell script using an elevated PowerShell prompt. That will give you an HTML file in the folder in the last line of the script, in my case C:\inetpub\wwwroot\default.htm. Open that with any web browser and you should be done. However, to work you do need to enable the monitor feature in MDT which is done in the Deployment Workbench (Enable Monitoring). If you would like to have the html file automatically created just create a normal scheduled tasks that runs the powershell script on a regular basis. I hope that helps, otherwise, let mw know.

  2. Hello Master! Must permanently store the MDT monitoring information, it seems that it excludes infromações every 3 days, it is possible to permanently store?

  3. Do you think it would be possible to gather info from multiple MDT servers?

    I have a number of MDT setups and it would be great to have an overview of them all on one webpage.

  4. Very handy ..Gr8 work
    But i am having mention below error any idea

    =========
    ForEach-Object : Cannot bind parameter ‘Process’. Cannot convert the “test\output\default.htm” value of type “System.String” to type “System.Management.Automation.ScriptBlock”.
    At C:\Users\evehqu\Desktop\scripts test\MDT monitoring.ps1:43 char:8
    + ForEach <<<< {
    + CategoryInfo : InvalidArgument: (:) [ForEach-Object], ParameterBindingException
    + FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Microsoft.PowerShell.Commands.ForEachObjectCommand
    ========

  5. Gr8 work,
    but i am having mention below error … need you help

    ======
    ForEach-Object : Cannot bind parameter ‘Process’. Cannot convert the “test\output\default.htm” value of type “System.String” to type “System.Management.Automation.ScriptBlock”.
    At C:\Users\test\Desktop\scripts test\GenOSDStatus.ps1:43 char:8
    + ForEach <<<< {
    + CategoryInfo : InvalidArgument: (:) [ForEach-Object], ParameterBindingException
    + FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Microsoft.PowerShell.Commands.ForEachObjectCommand
    ======

  6. Is it possible to have our own custom fields in MDT monitoring; Example want Business unit, Cubicle Number etc. apart from the default fields.

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.