I have done same blogposts that includes the usage of the MDT Monitor:
and they all use the same basic function.
During class last week I’ve got the question (You know who you are) –Is it possible to get the Dart information? and just two days later I’ve got on other question on how to extract the Step name, so, here it is a slightly updated and modified PowerShell function that will extract data from the MDT Monitor OData feed without the use of any MDT binary’s.
The updated Function:
Function Get-MDTOData{ <# .Synopsis Function for getting MDTOdata .DESCRIPTION Function for getting MDTOdata .EXAMPLE Get-MDTOData -MDTMonitorServer MDTSERVER01 .NOTES Created: 2016-03-07 Version: 1.0 Author - Mikael Nystrom Twitter: @mikael_nystrom Blog : http://deploymentbunny.com .LINK http://www.deploymentbunny.com #> Param( $MDTMonitorServer ) $URL = "http://" + $MDTMonitorServer + ":9801/MDTMonitorData/Computers" $Data = Invoke-RestMethod $URL foreach($property in ($Data.content.properties) ){ $Hash = [ordered]@{ 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"} } ); StepName = $($property.StepName); TotalSteps = $($property.TotalStepS.'#text') CurrentStep = $($property.CurrentStep.'#text') DartIP = $($property.DartIP); DartPort = $($property.DartPort); DartTicket = $($property.DartTicket); VMHost = $($property.VMHost.'#text'); VMName = $($property.VMName.'#text'); LastTime = $($property.LastTime.'#text') -replace "T"," "; StartTime = $($property.StartTime.’#text’) -replace "T"," "; EndTime = $($property.EndTime.’#text’) -replace "T"," "; } New-Object PSObject -Property $Hash } }
And is here some examples on how you can use the data:
Pure Vanilla Commandline:
Get-MDTOData -MDTMonitorServer SRVMDT01
Using GridView
Get-MDTOData -MDTMonitorServer SRVMDT01 | Out-GridView
Create a WebPage
$Title = "ViaMonstra Deployment Status" $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>" Get-MDTOData -MDTMonitorServer SRVMDT01 | Sort -Property Name | ConvertTo-Html ` -Title $Title ` -Head $Head ` -Body (Get-Date -UFormat "%Y-%m-%d - %T ") ` -PreContent "<H2>$Title for: $ENV:COMPUTERNAME </H2><P>Generated by Power of the Force</P>" ` -PostContent "<P>For details, contact support@viamonstra.com</P>" ` -Property Name,PercentComplete,Warnings,Errors,DeploymentStatus,StepName,TotalSteps,CurrentStep,DartIP,DartPort,DartTicket,VMHost,VMName,LastTime,StartTime,EndTime | 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
You can also download and use this Module directly from https://www.powershellgallery.com/packages/GetMDTOdataModule/1.0 by running the following command in PowerShell (version 5)
Find-Module GetMDTOdataModule | Install-Module -Scope CurrentUser
/mike
Categories: MDT, PowerShell
What’s the best way to make this a background process? I was going to do task scheduler but then I realized there would be a window popping up every 5 minutes.
I usally create “serviceAccount” and use that, runs minimized as a task, either kicked of by an event or time, that way it never pops up
Hi Mike.
I installed the module as instructed from the powershellgallery, but when I run Get-MDTOData -MDTMonitorServer SRVMDT01 | Out-GridView – I get:
Get-MDTOData : The term ‘Get-MDTOData’ is not recognized as the name of a cmdlet, function, script file, or operable pr
ogram. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1
+ Get-MDTOData -MDTMonitorServer mdt2013u1.dgi.ds | Out-GridView
+ ~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (Get-MDTOData:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
Why is this?
Check if the module is installed, run Get-Module, if it is installed. The message you get indicates that is not installed
I do se it if i run Get-Module but it does not contain any commands.
The ExportedCommands is empty.
Ok, I’ll check and get back later today
i got a nice little question for you…
i would like to also see what the current task used is!
i tried to find out all things you can read from this script but i fail to find something corresponding to the Tasksequence ID or whatever …
room for improvement?
(Something failed with my other post, i think so if this is a double-post please remove this one)