MSEndpointMgr

Create a Deployment Summary HTML Report with PowerShell

I’ve always wanted to have a nice report emailed to me each Monday morning showing what have been deployed during the weekend and how it went. Up until now I’ve gone into the Configuration Manager 2012 console and fired off a report giving me that information. But wouldn’t it be nice to automate that process and have it sent to you by email? I think so, so I started looking into creating HTML reports. I found Jefferey Hicks script “Morning Report” (can be found here). I re-wrote the script and added some cool rows so that I could get the output that I wanted from the SMS_DeploymentSummary class in WMI.

The Script

Save the script as DeploymentReport.ps1 in e.g. C:\Scripts.

$ComputerName=$env:computername
$ReportTitle="System Report"
[string]$reportVersion="1.0"
$head = @"
<style>
body { background-color:#FFFFFF;
font-family:Tahoma;
font-size:12pt; }
td, th { border:1px solid #000033; 
border-collapse:collapse; }
th { color:white;
background-color:#800517; }
table, tr, td, th { padding: 2px; margin: 0px }
table { margin-left:50px; }
</style>
<Title>$ReportTitle</Title>
"@
#Computer system
$cs = Get-WmiObject -Class Win32_Computersystem -ComputerName $computername
$csdata = $cs | Select Status,Manufacturer,Model,SystemType,Number*
#Deployment Summary
$timeSpan = (Get-Date).Adddays(-<number of days ago>)
$GetDeployments = Get-WmiObject -Namespace "root\sms\site_p01" -Class SMS_DeploymentSummary -ComputerName $ComputerName | Where-Object {($_.FeatureType -eq "1") -AND ($_.CollectionName -like "*<collection>*") -AND ($_.ConvertToDateTime($_.CreationTime) -gt $timeSpan)}
$deploymentSummary = $GetDeployments | Select-Object CollectionName,@{Label="CreationTime";Expression={$_.ConvertToDateTime($_.CreationTime)}},@{Label="Deployment";Expression={$_.SoftwareName}},NumberSuccess,NumberInProgress,NumberOther,NumberErrors,FeatureType
#Write results depending on parameter set
$footer="Report v{3} run {0} by {1}\{2}" -f (Get-Date),$env:USERDOMAIN,$env:USERNAME,$reportVersion
#Prepare HTML code
$fragments = @()
#Insert a graphic header
$fragments += "<Img src='https://www.yoursite.com/logo.jpg' style='float:left' width='197' height='78' hspace=10><H1> The Deployment Summary Report</H1><br><br>"
$fragments += $csdata | ConvertTo-HTML -Fragment -PreContent "<H2>Computer System</H2>"
$fragments += $deploymentsummary | ConvertTo-HTML -Fragment -PreContent "<H2>Deployment Summary</H2>"
Write $fragments | clip
ConvertTo-Html -Head $head -Title $ReportTitle -PreContent ($fragments | out-String) -PostContent "<br><I>$footer</I>"

Running the report as a scheduled task

In order to get the output from the script above, we will need to save the output to a HTML file. We’d also like to email the HTML file to a recipient. To do so, we create a small script to handle that:

$ScriptPath = "C:\Scripts\DeploymentReport.ps1"
$OutFile = "E:\Scripts\DeploymentReport.html"
$ComputerName = "<siteserver>"
Invoke-Expression "$($ScriptPath) -ComputerName $($ComputerName) | Out-File $($OutFile)"
Send-MailMessage -SmtpServer "<smtpserverFQDN>" -To "[email protected]" -From "[email protected]" -Subject "Deployment Summary Report" -Body "Please see attached file." -Attachments $OutFile
Get-Item $OutFile | Remove-Item -Force

Save this script as InvokeDeploymentReport.ps1 in C:\Scripts.
1. Open Task Scheduler and create a new task.
2. On the General tab, give the new task a name, e.g. Deployment Summary Report. Select Run whether user is logged on or not.
3. On the Triggers tab, configure as the image below:

 
4. On the Actions tab, click New and in the Program/script field type PowerShell “C:\Scripts\InvokeDeploymentReport.ps1”.

5. When prompted as in the picture below, click Yes.

6. Click OK in the Create Task window, and when prompted for credentials it’s imported that you supply an user account that has the Full Administrator role in Configuration Manager.

The actual report

When the scheduled task kicks off, you’ll receive an email with an attachment called DeploymentReport.html. This is how the report looks like:

This report will only show the latest Applications deployments. If you’d like to get Software Update deployments aswell, you can replace the following line in DeploymentReport.ps1:

$GetDeployments = Get-WmiObject -Namespace "root\sms\site_p01" -Class SMS_DeploymentSummary -ComputerName TRI-STO-CM01 | Where-Object {($_.FeatureType -eq "1") -AND ($_.CollectionName -like "*workstation*") -AND ($_.ConvertToDateTime($_.CreationTime) -gt $timeSpan)}

to:

$GetDeployments = Get-WmiObject -Namespace "root\sms\site_p01" -Class SMS_DeploymentSummary -ComputerName TRI-STO-CM01 | Where-Object {($_.FeatureType -eq "1") -OR ($_.FeatureType -eq "5") -AND ($_.CollectionName -like "*workstation*") -AND ($_.ConvertToDateTime($_.CreationTime) -gt $timeSpan)}

Nickolaj Andersen

Chief Technical Architect and Enterprise Mobility MVP since 2016. Nickolaj has been in the IT industry for the past 10 years specializing in Enterprise Mobility and Security, Windows devices and deployments including automation. Awarded as PowerShell Hero in 2015 by the community for his script and tools contributions. Creator of ConfigMgr Prerequisites Tool, ConfigMgr OSD FrontEnd, ConfigMgr WebService to name a few. Frequent speaker at conferences such as Microsoft Ignite, NIC Conference and IT/Dev Connections including nordic user groups.

8 comments

  • Hi All,
    I understand this is old by now…
    Still as Reagan asked- anyone found where we can get the device details of deployment summary or the class related to it?..
    Would be a great help if that is possible.

  • Hi Nickolaj,
    Thanks for the reply, can you give a hint on what class should I use?
    Thanks!
    Regards,
    Reagan

    • Hi Reagan,
      I’m not aware of what those classes are as of the moment. But here’s a tip. I use this tool to browse the SMS Provider and explore the classes that I might be interrested in when I’m working on a script:
      https://wmie.codeplex.com/Wikipage?ProjectName=wmie
      Additionally, the SMSProv.log is also a very good log to find out information. This file logs all of the actions that you take in the console, and from that you can find out what classes was queried in order to get the information that you requested.
      Regards,
      Nickolaj

    • Hi Reagan,
      The device names are unfortunately not available in the SMS_DeploymentSummary WMI class, so by using this script only it’s not possible to get the device names as well. That information is stored in different classes, and it would be necessary to re-write the whole script basically.
      Regards,
      Nickolaj

Sponsors

Categories

MSEndpointMgr.com use cookies to ensure that we give you the best experience on our website.