Overview

When OMS pushes a new solution pack to Operations Manager, there is no clear way to know when this has been done.

This script will query the Operational Database and return results of any updates.

It's set by default to query the last 24 hours, but that can be easily adjusted by modifying the query in the script.

It outputs it's findings to a log file, and will send an email, besides writing to the Operations Manager event log.  In this example there is a custom source of "MUScript" that I've set up.

SCOM is set to alert on this event.
Put the script into Task Scheduler and schedule it for every 24 hours, or a period you choose.

Script


# Script to monitor changes to SCOM Intelligence and Management Packs that are pushed from Microsoft.
# Script hashed together by Darren Joyce
# Last Update : 25/6/15
# Version 1.1
 
$mailsubject = "New Ops Insights Management Packs detected"
$mailrecipient = "myemail@xxxxx.com"
$mailsender = "scomalerting@xxxxx.com"
$mailserver = "smtp.xxxxx.com"
 
function Invoke-SQL {
param(
    [Parameter(Mandatory=$true)]
    [string]$Server,
    [Parameter(Mandatory=$true)]
    [string]$dbName,
    [Parameter(Mandatory=$true)]
    [string]$sqlQuery
)
  
$ConnectString="Data Source=${Server}; Integrated Security=SSPI; Initial Catalog=${dbName}"
  
$Conn=New-Object System.Data.SqlClient.SQLConnection($ConnectString)
$Command = New-Object System.Data.SqlClient.SqlCommand($sqlQuery,$Conn)
$Conn.Open()
  
$Adapter = New-Object System.Data.SqlClient.SqlDataAdapter $Command
$DataSet = New-Object System.Data.DataSet
$Adapter.Fill($DataSet) | Out-Null
  
$Conn.Close()
$DataSet.Tables
}
 
function mailresults
{
    [CmdletBinding()]                   # Allows us to define the ErrorAction to be taken when run
    Param()
    $Sent = $false                      # Flags mail as unsent
    [int]$Retrycount = "0"
     
    # Creates a loop that will attempt to retry sending of mail every 5 seconds for 5 attempts.
     
    do
    {
        try
        {
            #Sends mail
$body = $mplist
 
            send-mailmessage -To $mailrecipient -Subject $mailsubject -body ($body -join "`n")  -From $mailsender -smtpServer $mailserver
            $Sent = $true
            "Mail retry count: " + $Retrycount
        }
        catch                           # Catches any errors that may occur
        {
            if ($Retrycount -gt 5)      # Fails sending only if error count is larger than 5 attempts
            {
                Write-Host "Email failed after 5 attempts."
                $Stoploop = $true
            }
            else
            {
                Start-Sleep -Seconds 5  # Sleeps 5 seconds before re-attempt
                $Retrycount = $Retrycount + 1
            }
 
        }
    }
    While ($Sent -eq $false)
}
 
function writeevent {
 
   Write-EventLog -LogName 'Operations Manager' -Source "MUScript" -EntryType Warning -EventId 1001 -Message "New OMS Solution Packs have been pushed: $mplist"
}
 
function writelog {
$date = Get-Date -UFormat "%d.%m.%Y"
$mplist  | out-file c:\log\MPUpdates_opsinsights\$date.MPUpdates_opsinsights.txt
start-sleep -s 1
}
 
 
#This line will check the last 24 hours from when the script was run.
$mplist = (Invoke-Sql -dbname "OperationsManager" -SQLquery "use OperationsManager select * from ManagementPackHistory where TimeAdded > dateadd(hh,-24,getdate()) and MPName like '%advisor%' AND IsSealed LIKE '1' order by TimeAdded" -Server "TUR-SCOM-DB1") | select mpname, version, @{Name="LocalTime";expression={$_.timeadded.tolocaltime()}} | Sort-Object LocalTime -Descending | format-list | Out-String
 
Import-Module operationsmanager
 
 
 
 
if ($mplist){
writelog
mailresults
writeevent
}else
{write-host "no data"
}

SCOM Configuration.

A new Rule is configured to alert on this event being thrown in the Operations Manager Log.






Conclusion

A handy way to see when Microsoft push out updates to SCOM for OMS Solution Packs.