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='http://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 "recipient@domain.com" -From "from@domain.com" -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
Principal Consultant and Enterprise Mobility MVP. Nickolaj has been in the IT industry for the past 10 years specializing in Enterprise Mobility and Security, Windows deployments and Automation. In 2015 Nickolaj was awarded as PowerShell Hero by the community for his script and tools contributions. Author of ConfigMgr Prerequisites Tool, ConfigMgr OSD FrontEnd, ConfigMgr WebService and a frequent speaker at user groups.

(400)

comments
  • Reagan
    Posted at 12:21 May 2, 2014
    Reagan
    Reply
    Author

    How can you add the devices on this deployment summary?

    • Nickolaj
      Posted at 12:42 May 2, 2014
      Nickolaj
      Reply
      Author

      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

  • Reagan
    Posted at 14:06 May 2, 2014
    Reagan
    Reply
    Author

    Hi Nickolaj,

    Thanks for the reply, can you give a hint on what class should I use?

    Thanks!

    Regards,
    Reagan

    • Nickolaj
      Posted at 18:58 May 9, 2014
      Nickolaj
      Reply
      Author

      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

  • Reagan
    Posted at 06:34 May 11, 2014
    Reagan
    Reply
    Author

    Thanks Nikolaj. This would be a big help.

  • Lakshmi
    Posted at 15:27 February 12, 2016
    Lakshmi
    Reply
    Author

    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.

  • Matthew Quickenden
    Posted at 00:03 August 13, 2016
    Matthew Quickenden
    Reply
    Author

    Hi, I have created an HTML reporting module to help generate HTML code from within Powershell. You can group data, color rows, create sections, roll up sections and load your own logos and more all without any HTML coding. This will work with any Powershell data set. Follow this link for code and examples, it is also loaded in github for collaborative development.

    http://www.azurefieldnotes.com/2016/08/04/powershellhtmlreportingpart1/

  • analyzer
    Posted at 22:57 January 13, 2017
    analyzer
    Reply
    Author

    Incredible quite a lot of helpful knowledge!

  • Leave a Reply