Share via


Software Updates Deployments - Notification Script Update

In the last blog post the code used was also triggering notifications for Configuration Baselines.  EventIDs 30196 and 30197 are also used for Baseline deployments.  If we run the query in SQL Management Studio to retrieve all Assignments, we can see that there is an AssignmentType, and looking at that table gives us the following info:

AssignmentType

A quick modification to the query to include the AssignmentType, and then an if statement to only continue the script if AssignmentType = 5 will get the job done.

DISCLAIMER: The information on this site is provided "AS IS" with no warranties, confers no rights, and is not supported by the authors or Microsoft Corporation.  Please test any/all information here in a test environment before running on a production network.

SCCM_Software_Update_Events.ps1 - View on GitHub Gist

001002003004005006007008009010011012013014015016017018019020021022023024025026027028029030031032033034035036037038039040041042043044045046047048049050051052053054055056057058059060061062063064065066067068069070071 param($msgID, $AssignmentID) trap { $_ | Out-File -FilePath C:\TEMP\sccm_scripting_error.txt -Force } ## USER CONFIG ############################################## #$email_to = "joe@northwinds.local" #$email_from = "noreply@northwinds.local" #$email_server = "192.168.1.1" # SQL\SERVERNAME\INSTANCE\Databases\DATABASENAME $sqlString = "SQL\SCCMCAS\DEFAULT\Databases\CM_CAS" #############################################################   New-EventLog -LogName Application -Source "SMS Scripting" -ErrorAction SilentlyContinue   Import-Module SQLPS   Set-Location $sqlString   $query = Invoke-Sqlcmd -Query "SELECT VCIA.AssignmentId, VCIA.AssignmentName, VCIA.UseGMTTimes, VCIA.CreationTime, VCIA.LastModifiedBy, VCIA.LastModificationTime, VCIA.StartTime, VCIA.EnforcementDeadline, VCIA.SourceSite, COLS.CollectionName, SRV.SiteCode, CMC.AssignedCount, VCIA.AssignmentType FROM vCI_CIAssignments VCIA INNER JOIN Collections COLS ON COLS.CollectionID = VCIA.TargetCollectionID INNER JOIN CollectionMemberCounts CMC ON CMC.CollectionID = COLS.COllectionID INNER JOIN ServerData SRV ON SRV.ID = CMC.SiteNumber WHERE VCIA.AssignmentID = $AssignmentID;"   $info = "" if($query[0].AssignmentId -eq $AssignmentID) { $info = $query[0] } else { $info = $query } if($info.AssignmentType -eq 5) {     $totalCount = 0     foreach($rec in $query) { $totalCount += $rec.AssignedCount }       $message = ""     switch($msgID)     {         30196 { $message = "Updates Deployment CREATED on '$($info.CollectionName)' targeting $totalCount machine(s).`r`n`r`n" }         30197 { $message = "Updates Deployment MODIFIED on '$($info.CollectionName)' targeting $totalCount machine(s).`r`n`r`n" }         Default { $message = "Unhandled msgID was passed." }     }       $message += "AssignmentID: $($info.AssignmentID)`r`n"     $message += "AssignmentName: $($info.AssignmentName)`r`n"     $message += "CreationTime: $($info.CreationTime)`r`n"     $message += "LastModifiedBy: $($info.LastModifiedBy)`r`n"     $message += "LastModificaitonTime: $($info.LastModificationTime)`r`n"     $message += "StartTime: $($info.StartTime)"     if($info.UseGMTTimes) { $message += " UTC" }     $message += "`r`n"     if($info.EnforcementDeadline.ToString().Trim() -eq "")     {         $message += "EnforcementDeadLine: (None - Available Deployment)`r`n"     } else {         $message += "EnforcementDeadLine: $($info.EnforcementDeadline)"         if($info.UseGMTTimes) { $message += " UTC" }         $message += "`r`n"     }     $message += "CollectionName: $($info.CollectionName)`r`n"     foreach($rec in $query) { $message += "$($rec.SiteCode) AssignedCount: $($rec.AssignedCount)`r`n" }     $message += "TotalCount: $totalCount`r`n"       Write-EventLog -LogName Application -Source "SMS Scripting" -EntryType Information -EventId $msgID -Message $message       #$email = New-Object System.Net.Mail.MailMessage     #$email.To.Add($email_to)     #$email.From = $email_from     #$email.Subject = "SCCM 2012 | $($info.SourceSite) Updates Deployment | $totalCount Targets"     #$email.Body = $message     #$smtp = New-Object System.Net.Mail.SmtpClient $email_server     #$smtp.Send($email) } # #