If it’s more than one person working with Configuration Manager (yeah like you do it all by yourself ;).
It can be hard to keep up, a new application added on Monday, a Package modified on Tuesday and 3 new Configuration Items on Friday.
This script will hopefully makes it a little bit easier to keep up.
The Basics
1. First we need to gather some information
1 2 |
$NewDeployments = Get-CMApplication | ? DateCreated -gt (get-date).AddDays($DaysToShow)| Select LocalizedDisplayName,LastModifiedBy, DateCreated | Sort-Object DateCreat |
2. If something is returned, add it to a text file with a little html formatting
1 2 3 4 5 |
if ($NewDeployments -ne $null ) { New-Table -Title "New Deployments" -Topic1 "SoftwareName" -Topic2 "Deployed to" -Topic3 "CreationTime" foreach ($app in $NewDeployments ) {New-TableRow -col1 $app.SoftwareName -col2 $app.CollectionName -col3 $app.CreationTime} New-TableEnd } |
3. Send it as a nicely html formatted email.
I run this script (scheduled task) every Monday morning, perfect reading while enjoying  my morning coffee 🙂
The Script
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 |
# Import ConfigMgr Module Import-Module ($env:SMS_ADMIN_UI_PATH.Substring(0,$env:SMS_ADMIN_UI_PATH.Length – 5) + 'ConfigurationManager.psd1') # - - - Settings - - - $SiteCode = '007:' # Number of days in report $DaysToShow = '-7' # Mail settings $smtpserver = "your.smtp.server" $MailSubject = "ConfigMgr Week Report" $MailRecipients = "CMAdministrator@domain.com","CMPoweUser@domain.com" $FromAddress = "cmreports@domain.com" # Tempfile to store data $msgfile = 'c:tempmailmessage.txt' # - - - End Settings - - - # Create file New-Item $msgfile -ItemType file -Verbose -Force Set-Location $SiteCode $StartTime = (Get-Date) # Get data from ConfigMgr $NewApplications = Get-CMApplication | ? DateCreated -gt (get-date).AddDays($DaysToShow) | Select LocalizedDisplayName,LastModifiedBy, DateCreated | Sort-Object DateCreated $ModifiedApplications = Get-CMApplication | ? DateLastModified -gt (get-date).AddDays($DaysToShow) | Select LocalizedDisplayName,LastModifiedBy, DateLastModified | Sort-Object DateLastModified $NewCI = Get-CMConfigurationItem | ? DateCreated -gt (get-date).AddDays($DaysToShow) | Select LocalizedDisplayName,LastModifiedBy, DateCreated | Sort-Object DateCreated $ModifiedCI = Get-CMConfigurationItem | ? DateLastModified -gt (get-date).AddDays($DaysToShow) | Select LocalizedDisplayName,LastModifiedBy, DateLastModified | Sort-Object DateLastModified $NewBaselines = Get-CMBaseline | ? DateCreated -gt (get-date).AddDays($DaysToShow) | Select LocalizedDisplayName,LastModifiedBy, DateCreated | Sort-Object DateCreated $ModifiedBaselines = Get-CMBaseline | ? DateLastModified -gt (get-date).AddDays($DaysToShow) | Select LocalizedDisplayName,LastModifiedBy, DateLastModified | Sort-Object DateLastModified $DriverPackages = Get-CMDriverPackage | ? SourceDate -gt (get-date).AddDays($DaysToShow) | Select Name,SourceDate | Sort-Object SourceDate $NewBoundarys = Get-CMBoundary | ? CreatedOn -gt (Get-Date).AddDays($DaysToShow) | Select DisplayName, ModifiedBy ,CreatedOn | Sort-Object CreatedOn $ModifiedBoundarys = Get-CMBoundary | ? ModifiedOn -gt (Get-Date).AddDays($DaysToShow) | Select DisplayName, ModifiedBy, ModifiedOn | Sort-Object ModifiedOn $NewDeployments = Get-CMDeployment | ? CreationTime -gt (Get-Date).AddDays($DaysToShow) | Select CollectionName,CreationTime,SoftwareName | Sort-Object CreationTime $Bootimages = Get-CMBootImage | ? SourceDate -gt (Get-Date).AddDays($DaysToShow) | Select Name,Description,SourceDate | Sort-Object SourceDate $Packages = Get-CMPackage | ? SourceDate -gt (get-date).AddDays($DaysToShow) | Select Name,SourceDate | Sort-Object SourceDate $EndTime = (Get-Date) function New-Table ( $Title, $Topic1, $Topic2, $Topic3 ) { Add-Content $msgfile "<h3>$Title</h3>" Add-Content $msgfile "<p><table cellspacing=""15"">" Add-Content $msgfile "<tr><th>$Topic1</th><th>$Topic2</th><th>$Topic3</th></tr>" } function New-TableRow ( $col1, $col2, $col3 ) { Add-Content $msgfile "<tr><td>$col1</td><td>$col2</td><td>$col3</td></tr>" } function New-TableEnd { Add-Content $msgfile "</table></p>"} if ($NewDeployments -ne $null ) { New-Table -Title "New Deployments" -Topic1 "SoftwareName" -Topic2 "Deployed to" -Topic3 "CreationTime" foreach ($app in $NewDeployments ) {New-TableRow -col1 $app.SoftwareName -col2 $app.CollectionName -col3 $app.CreationTime} New-TableEnd } if ($NewApplications -ne $null ) { New-Table -Title "New Applications" -Topic1 "LocalizedDisplayName" -Topic2 "LastModifiedBy" -Topic3 "DateCreated" foreach ($app in $NewApplications ) {New-TableRow -col1 $app.LocalizedDisplayName -col2 $app.LastModifiedBy -col3 $app.DateCreated} New-TableEnd } if ($ModifiedApplications -ne $null ) { New-Table -Title "Modified Applications" -Topic1 "LocalizedDisplayName" -Topic2 "LastModifiedBy" -Topic3 "DateLastModified" foreach ($app in $ModifiedApplications ) {New-TableRow -col1 $app.LocalizedDisplayName -col2 $app.LastModifiedBy -col3 $app.DateLastModified} New-TableEnd } if ($Packages -ne $null ) { New-Table -Title "New/Modified Packages" -Topic1 "Name" -Topic2 "SourceDate" foreach ($app in $Packages ) {New-TableRow -col1 $app.Name -col2 $app.SourceDate} New-TableEnd } if ($DriverPackages -ne $null ) { New-Table -Title "New/Modified Driver Packages" -Topic1 "Name" -Topic2 "SourceDate" foreach ($app in $DriverPackages ) {New-TableRow -col1 $app.Name -col2 $app.SourceDate} New-TableEnd } if ($NewCI -ne $null ) { New-Table -Title "New CI's" -Topic1 "LocalizedDisplayName" -Topic2 "LastModifiedBy" -Topic3 "DateCreated" foreach ($app in $NewCI ) {New-TableRow -col1 $app.LocalizedDisplayName -col2 $app.LastModifiedBy -col3 $app.DateCreated} New-TableEnd } if ($ModifiedCI -ne $null ) { New-Table -Title "Modified CI's" -Topic1 "LocalizedDisplayName" -Topic2 "LastModifiedBy" -Topic3 "DateLastModified" foreach ($app in $ModifiedCI ) {New-TableRow -col1 $app.LocalizedDisplayName -col2 $app.LastModifiedBy -col3 $app.DateLastModified} New-TableEnd } if ($NewBaselines -ne $null ) { New-Table -Title "New Baselines's" -Topic1 "LocalizedDisplayName" -Topic2 "LastModifiedBy" -Topic3 "DateCreated" foreach ($app in $NewBaselines ) {New-TableRow -col1 $app.LocalizedDisplayName -col2 $app.LastModifiedBy -col3 $app.DateCreated} New-TableEnd } if ($ModifiedBaselines -ne $null ) { New-Table -Title "Modified Baselines" -Topic1 "LocalizedDisplayName" -Topic2 "LastModifiedBy" -Topic3 "DateLastModified" foreach ($app in $ModifiedBaselines ) {New-TableRow -col1 $app.LocalizedDisplayName -col2 $app.LastModifiedBy -col3 $app.DateLastModified} New-TableEnd } if ($NewBoundarys -ne $null ) { New-Table -Title "New Boundarys" -Topic1 "DisplayName" -Topic2 "ModifiedBy" -Topic3 "CreatedOn" foreach ($app in $NewBoundarys ) {New-TableRow -col1 $app.DisplayName -col2 $app.ModifiedBy -col3 $app.CreatedOn} New-TableEnd } if ($ModifiedBoundarys -ne $null ) { New-Table -Title "Modified Boundarys" -Topic1 "DisplayName" -Topic2 "ModifiedBy" -Topic3 "ModifiedOn" foreach ($app in $ModifiedBoundarys ) {New-TableRow -col1 $app.DisplayName -col2 $app.ModifiedBy -col3 $app.ModifiedOn} New-TableEnd } if ($Bootimages -ne $null ) { New-Table -Title "New/Modified Boot Images" -Topic1 "Name" -Topic2 "Description" -Topic3 "SourceDate" foreach ($app in $Bootimages ) {New-TableRow -col1 $app.Name -col2 $app.Description -col3 $app.SourceDate} New-TableEnd } Add-Content $msgfile "<p>Data collected in $(($EndTime-$StartTime).totalseconds) seconds</p>" $mailbody = Get-Content $msgfile Send-MailMessage -Body "$mailbody" -From $FromAddress -to $MailRecipients -SmtpServer $smtpserver -Subject $MailSubject -BodyAsHtml # Delete tempfile Remove-Item $msgfile |
Happy PowerReporting Andreas 🙂
Hi, thanks for this post! How long should this script normally take to run? I’ve configured it and I can see that its created the txt file but nothing has been written to it yet (Running SCCM 2012 R2 CU1 with SQL on box with latest version of PowerShell)
Cheers
Never mind, it has finished, took around 3 minutes. Should have waited longer!
yeah it’s take some time to run. For me it’s a bit over 2 minutes.
It would go a hole lotta a faster to call WMI directly instead of using the PowerShell module.
But this way was easier =)
Top post. great script! works a treat!
Thanks’ 🙂