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:
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:
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




Reblogged this on MDTGuy.WordPress.com and commented:
The Deployment Bunny delivers gold again!
LikeLike
Powershell Por Vida!
LikeLike
This is awesome! Have you been able to throw some CSS on it to get nicer formatting?
I could see myself using this during a deployment project.
LikeLike
Reblogged this on Things that cross my mind… and commented:
Love the idea of being able to give people the ability to see how a lab deployment is going without giving access to the MDT console.
LikeLike
Is it possible to get the same type of info from config manager and output to a webpage?
thanks
S
LikeLike
Yes, using the integration with MDT, create a “dummy” deploymentshare, configure the cs.ini will do the thing.
LikeLike
Very cool! Thanks!
LikeLike
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,
LikeLike
that feels like a perfect thing to do during this week, going to BUILD 2014 and i’ll guess there will be some time for tha.
/mike
LikeLike
Thats great, about to start a deployment and this would be very helpful!
Thanks,
LikeLike
Did you manage to get anytime to write this Mike? :)
LikeLike
Shame this never happened. Anyone else know of a step by step guide?
LikeLike
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.
LikeLike
Great work! Thanks for the info – We’ve done a similar thing with an aspx front end to allow sorting and filtering – John http://justanotheritblog.co.uk/
LikeLike
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?
LikeLike
Yes, well, kind of, it id possible to store the data somewhere else, it could be possible to feed it back to the MDT DB
LikeLike
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.
LikeLike
Yes, that would be really cool and it can be done, let me play with that during the weekend!!!
LikeLike
Awesome, look forward to seeing it!
LikeLike
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
========
LikeLike
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
======
LikeLike
Is it possible to have our own custom fields in MDT monitoring; Example want Business unit, Cubicle Number etc. apart from the default fields.
LikeLike
Yes, tell me what you need exactly…
LikeLike