Disable all alerts for a SCOM management pack using PowerShell

So use this wisely…

This script will use Out-Gridview to prompt the operator for the management pack to disable the alerts for and the override management pack to save those overrides in.

Enjoy!
Dan

First, the script to do this for all monitors:
<pre><span style=”color: #5f9ea0; font-weight: bold;”>Import-module</span> <span style=”color: #800000;”>operationsmanager</span>

<span style=”color: #800080;”>$SCOMServer</span> <span style=”color: #ff0000;”>=</span> <span style=”color: #800000;”>”</span><span style=”color: #800000;”>&lt;SCOMServerName&gt;</span><span style=”color: #800000;”>”</span><span style=”color: #000000;”>
New-SCOMManagementGroupConnection -ComputerName </span><span style=”color: #800080;”>$SCOMServer</span>

<span style=”color: #800080;”>$MPSource</span> <span style=”color: #ff0000;”>=</span><span style=”color: #000000;”> get-scommanagementpack -ComputerName </span><span style=”color: #800080;”>$SCOMServer</span><span style=”color: #000000;”> | </span><span style=”color: #5f9ea0; font-weight: bold;”>where</span><span style=”color: #000000;”> {</span><span style=”color: #800080;”>$_</span><span style=”color: #000000;”>.Sealed </span><span style=”color: #ff0000;”>-eq</span> <span style=”color: #800080;”>$True</span><span style=”color: #000000;”>} | </span><span style=”color: #5f9ea0; font-weight: bold;”>Out-GridView</span> <span style=”color: #5f9ea0; font-style: italic;”>-Title</span> <span style=”color: #800000;”>”</span><span style=”color: #800000;”>Select a single SOURCE Management Pack</span><span style=”color: #800000;”>”</span> <span style=”color: #5f9ea0; font-style: italic;”>-PassThru</span>
<span style=”color: #800080;”>$MPOverride</span> <span style=”color: #ff0000;”>=</span><span style=”color: #000000;”> get-scommanagementpack -ComputerName </span><span style=”color: #800080;”>$SCOMServer</span><span style=”color: #000000;”> | </span><span style=”color: #5f9ea0; font-weight: bold;”>where</span><span style=”color: #000000;”> {</span><span style=”color: #800080;”>$_</span><span style=”color: #000000;”>.Sealed </span><span style=”color: #ff0000;”>-eq</span> <span style=”color: #800080;”>$False</span><span style=”color: #000000;”>} | </span><span style=”color: #5f9ea0; font-weight: bold;”>Out-GridView</span> <span style=”color: #5f9ea0; font-style: italic;”>-Title</span> <span style=”color: #800000;”>”</span><span style=”color: #800000;”>Select a single TARGET Management Pack</span><span style=”color: #800000;”>”</span> <span style=”color: #5f9ea0; font-style: italic;”>-PassThru</span>

<span style=”color: #5f9ea0; font-weight: bold;”>Write-Host</span> <span style=”color: #800000;”>””</span>
<span style=”color: #5f9ea0; font-weight: bold;”>Write-Host</span> <span style=”color: #5f9ea0; font-style: italic;”>-ForegroundColor</span> <span style=”color: #800000;”>Red</span> <span style=”color: #800000;”>”</span><span style=”color: #800000;”>!!!!!!! WARNING !!!!!!!</span><span style=”color: #800000;”>”</span>
<span style=”color: #5f9ea0; font-weight: bold;”>Write-Host</span> <span style=”color: #800000;”>””</span>
<span style=”color: #5f9ea0; font-weight: bold;”>Write-host</span> <span style=”color: #800000;”>”</span><span style=”color: #800000;”>All Monitors in MP </span><span style=”color: #800000;”>”</span> <span style=”color: #800080;”>$MPSource</span><span style=”color: #000000;”>.Name </span><span style=”color: #800000;”>”</span><span style=”color: #800000;”>will have</span><span style=”color: #800000;”>”</span>
<span style=”color: #5f9ea0; font-weight: bold;”>Write-Host</span> <span style=”color: #800000;”>”</span><span style=”color: #800000;”>an override create that sets the Generate Alert value to False.</span><span style=”color: #800000;”>”</span>
<span style=”color: #5f9ea0; font-weight: bold;”>Write-Host</span> <span style=”color: #800000;”>””</span>
<span style=”color: #5f9ea0; font-weight: bold;”>Write-Host</span> <span style=”color: #800000;”>”</span><span style=”color: #800000;”>Overrides will be saved to</span><span style=”color: #800000;”>”</span> <span style=”color: #800080;”>$MPOverride</span><span style=”color: #000000;”>.name
</span><span style=”color: #5f9ea0; font-weight: bold;”>Write-Host</span> <span style=”color: #800000;”>””</span>
<span style=”color: #5f9ea0; font-weight: bold;”>Write-Host</span> <span style=”color: #800000;”>””</span>
<span style=”color: #800080;”>$Proceed</span> <span style=”color: #ff0000;”>=</span> <span style=”color: #5f9ea0; font-weight: bold;”>Read-Host</span> <span style=”color: #800000;”>”</span><span style=”color: #800000;”>Type ‘Apply’ to continue</span><span style=”color: #800000;”>”</span>
<span style=”color: #0000ff;”>If</span><span style=”color: #000000;”>(</span><span style=”color: #800080;”>$Proceed</span> <span style=”color: #ff0000;”>-eq</span> <span style=”color: #800000;”>”</span><span style=”color: #800000;”>Apply</span><span style=”color: #800000;”>”</span><span style=”color: #000000;”>)
{
</span><span style=”color: #800080;”>$Monitors</span><span style=”color: #ff0000;”>=</span><span style=”color: #800080;”>$MPSource</span><span style=”color: #000000;”>|Get-SCOMMonitor -ComputerName </span><span style=”color: #800080;”>$SCOMServer</span><span style=”color: #000000;”> |?{</span><span style=”color: #800080;”>$_</span><span style=”color: #000000;”>.xmltag </span><span style=”color: #ff0000;”>-eq</span> <span style=”color: #800000;”>”</span><span style=”color: #800000;”>UnitMonitor</span><span style=”color: #800000;”>”</span><span style=”color: #000000;”>}
</span><span style=”color: #0000ff;”>ForEach</span><span style=”color: #000000;”>(</span><span style=”color: #800080;”>$Monitor</span> <span style=”color: #0000ff;”>in</span> <span style=”color: #800080;”>$Monitors</span><span style=”color: #000000;”>)
{
</span><span style=”color: #0000ff;”>If</span><span style=”color: #000000;”>(</span><span style=”color: #800080;”>$Monitor</span><span style=”color: #000000;”>.AlertSettings.AlertOnState </span><span style=”color: #ff0000;”>-ne</span> <span style=”color: #800080;”>$null</span><span style=”color: #000000;”>)
{
</span><span style=”color: #800080;”>$Target</span><span style=”color: #ff0000;”>=</span><span style=”color: #000000;”> Get-SCOMClass -ComputerName </span><span style=”color: #800080;”>$SCOMServer</span><span style=”color: #000000;”> -id </span><span style=”color: #800080;”>$Monitor</span><span style=”color: #000000;”>.Target.id
</span><span style=”color: #800080;”>$OverrideName</span><span style=”color: #ff0000;”>=</span><span style=”color: #800080;”>$Monitor</span><span style=”color: #000000;”>.name</span><span style=”color: #ff0000;”>+</span><span style=”color: #800000;”>”</span><span style=”color: #800000;”>.Override</span><span style=”color: #800000;”>”</span>
<span style=”color: #800080;”>$Override</span> <span style=”color: #ff0000;”>=</span> <span style=”color: #5f9ea0; font-weight: bold;”>New-Object</span> <span style=”color: #800000;”>Microsoft.EnterpriseManagement.Configuration.ManagementPackMonitorPropertyOverride</span><span style=”color: #000000;”>(</span><span style=”color: #800080;”>$MPOverride</span><span style=”color: #000000;”>,</span><span style=”color: #800080;”>$OverrideName</span><span style=”color: #000000;”>)
</span><span style=”color: #800080;”>$Override</span><span style=”color: #000000;”>.Monitor </span><span style=”color: #ff0000;”>=</span> <span style=”color: #800080;”>$Monitor</span>
<span style=”color: #800080;”>$Override</span><span style=”color: #000000;”>.Property </span><span style=”color: #ff0000;”>=</span> <span style=”color: #800000;”>”</span><span style=”color: #800000;”>GenerateAlert</span><span style=”color: #800000;”>”</span>
<span style=”color: #800080;”>$Override</span><span style=”color: #000000;”>.Value </span><span style=”color: #ff0000;”>=</span> <span style=”color: #800000;”>”</span><span style=”color: #800000;”>false</span><span style=”color: #800000;”>”</span>
<span style=”color: #800080;”>$Override</span><span style=”color: #000000;”>.Context </span><span style=”color: #ff0000;”>=</span> <span style=”color: #800080;”>$Target</span>
<span style=”color: #800080;”>$Override</span><span style=”color: #000000;”>.DisplayName </span><span style=”color: #ff0000;”>=</span> <span style=”color: #800080;”>$OverrideName</span><span style=”color: #000000;”>
}
}
</span><span style=”color: #800080;”>$MPOverride</span><span style=”color: #000000;”>.Verify()
</span><span style=”color: #800080;”>$MPOverride</span><span style=”color: #000000;”>.AcceptChanges()
Exit
}
</span><span style=”color: #0000ff;”>Else</span><span style=”color: #000000;”>
{
</span><span style=”color: #5f9ea0; font-weight: bold;”>Write-Host</span> <span style=”color: #800000;”>””</span>
<span style=”color: #5f9ea0; font-weight: bold;”>Write-Host</span> <span style=”color: #800000;”>”</span><span style=”color: #800000;”>User aborted process</span><span style=”color: #800000;”>”</span>
<span style=”color: #5f9ea0; font-weight: bold;”>Write-Host</span> <span style=”color: #800000;”>””</span>
<span style=”color: #5f9ea0;”>pause</span><span style=”color: #000000;”>
Exit
}
</span></pre>
Second, the script to do this for all rules:
<pre><span style=”color: #5f9ea0; font-weight: bold;”>Import-module</span> <span style=”color: #800000;”>operationsmanager</span>

<span style=”color: #800080;”>$SCOMServer</span> <span style=”color: #ff0000;”>=</span> <span style=”color: #800000;”>”</span><span style=”color: #800000;”>&lt;SCOMServerName&gt;</span><span style=”color: #800000;”>”</span><span style=”color: #000000;”>
New-SCOMManagementGroupConnection -ComputerName </span><span style=”color: #800080;”>$SCOMServer</span>

<span style=”color: #800080;”>$MPSource</span> <span style=”color: #ff0000;”>=</span><span style=”color: #000000;”> get-scommanagementpack -ComputerName </span><span style=”color: #800080;”>$SCOMServer</span><span style=”color: #000000;”> | </span><span style=”color: #5f9ea0; font-weight: bold;”>where</span><span style=”color: #000000;”> {</span><span style=”color: #800080;”>$_</span><span style=”color: #000000;”>.Sealed </span><span style=”color: #ff0000;”>-eq</span> <span style=”color: #800080;”>$True</span><span style=”color: #000000;”>} | </span><span style=”color: #5f9ea0; font-weight: bold;”>Out-GridView</span> <span style=”color: #5f9ea0; font-style: italic;”>-Title</span> <span style=”color: #800000;”>”</span><span style=”color: #800000;”>Select a single SOURCE Management Pack</span><span style=”color: #800000;”>”</span> <span style=”color: #5f9ea0; font-style: italic;”>-PassThru</span>
<span style=”color: #800080;”>$MPOverride</span> <span style=”color: #ff0000;”>=</span><span style=”color: #000000;”> get-scommanagementpack -ComputerName </span><span style=”color: #800080;”>$SCOMServer</span><span style=”color: #000000;”> | </span><span style=”color: #5f9ea0; font-weight: bold;”>where</span><span style=”color: #000000;”> {</span><span style=”color: #800080;”>$_</span><span style=”color: #000000;”>.Sealed </span><span style=”color: #ff0000;”>-eq</span> <span style=”color: #800080;”>$False</span><span style=”color: #000000;”>} | </span><span style=”color: #5f9ea0; font-weight: bold;”>Out-GridView</span> <span style=”color: #5f9ea0; font-style: italic;”>-Title</span> <span style=”color: #800000;”>”</span><span style=”color: #800000;”>Select a single TARGET Management Pack</span><span style=”color: #800000;”>”</span> <span style=”color: #5f9ea0; font-style: italic;”>-PassThru</span>

<span style=”color: #5f9ea0; font-weight: bold;”>Write-Host</span> <span style=”color: #800000;”>””</span>
<span style=”color: #5f9ea0; font-weight: bold;”>Write-Host</span> <span style=”color: #5f9ea0; font-style: italic;”>-ForegroundColor</span> <span style=”color: #800000;”>Red</span> <span style=”color: #800000;”>”</span><span style=”color: #800000;”>!!!!!!! WARNING !!!!!!!</span><span style=”color: #800000;”>”</span>
<span style=”color: #5f9ea0; font-weight: bold;”>Write-Host</span> <span style=”color: #800000;”>””</span>
<span style=”color: #5f9ea0; font-weight: bold;”>Write-host</span> <span style=”color: #800000;”>”</span><span style=”color: #800000;”>All Rules in MP </span><span style=”color: #800000;”>”</span> <span style=”color: #800080;”>$MPSource</span><span style=”color: #000000;”>.Name </span><span style=”color: #800000;”>”</span><span style=”color: #800000;”>will have</span><span style=”color: #800000;”>”</span>
<span style=”color: #5f9ea0; font-weight: bold;”>Write-Host</span> <span style=”color: #800000;”>”</span><span style=”color: #800000;”>an override create that sets the Generate Alert value to False.</span><span style=”color: #800000;”>”</span>
<span style=”color: #5f9ea0; font-weight: bold;”>Write-Host</span> <span style=”color: #800000;”>””</span>
<span style=”color: #5f9ea0; font-weight: bold;”>Write-Host</span> <span style=”color: #800000;”>”</span><span style=”color: #800000;”>Overrides will be saved to</span><span style=”color: #800000;”>”</span> <span style=”color: #800080;”>$MPOverride</span><span style=”color: #000000;”>.name
</span><span style=”color: #5f9ea0; font-weight: bold;”>Write-Host</span> <span style=”color: #800000;”>””</span>
<span style=”color: #5f9ea0; font-weight: bold;”>Write-Host</span> <span style=”color: #800000;”>””</span>
<span style=”color: #800080;”>$Proceed</span> <span style=”color: #ff0000;”>=</span> <span style=”color: #5f9ea0; font-weight: bold;”>Read-Host</span> <span style=”color: #800000;”>”</span><span style=”color: #800000;”>Type ‘Apply’ to continue</span><span style=”color: #800000;”>”</span>
<span style=”color: #0000ff;”>If</span><span style=”color: #000000;”>(</span><span style=”color: #800080;”>$Proceed</span> <span style=”color: #ff0000;”>-eq</span> <span style=”color: #800000;”>”</span><span style=”color: #800000;”>Apply</span><span style=”color: #800000;”>”</span><span style=”color: #000000;”>)
{
</span><span style=”color: #800080;”>$Rules</span><span style=”color: #ff0000;”>=</span><span style=”color: #800080;”>$MPSource</span><span style=”color: #000000;”> | Get-SCOMRule -ComputerName </span><span style=”color: #800080;”>$SCOMServer</span><span style=”color: #000000;”> | ?{</span><span style=”color: #800080;”>$_</span><span style=”color: #000000;”>.xmltag </span><span style=”color: #ff0000;”>-eq</span> <span style=”color: #800000;”>”</span><span style=”color: #800000;”>Rule</span><span style=”color: #800000;”>”</span><span style=”color: #000000;”>}
</span><span style=”color: #0000ff;”>ForEach</span><span style=”color: #000000;”>(</span><span style=”color: #800080;”>$Rule</span> <span style=”color: #0000ff;”>in</span> <span style=”color: #800080;”>$Rules</span><span style=”color: #000000;”>)
{
</span><span style=”color: #0000ff;”>If</span><span style=”color: #000000;”>(</span><span style=”color: #800080;”>$Rule</span><span style=”color: #000000;”>.Enabled </span><span style=”color: #ff0000;”>-ne</span> <span style=”color: #800000;”>'</span><span style=”color: #800000;”>True</span><span style=”color: #800000;”>'</span><span style=”color: #000000;”>)
{
Disable-SCOMRule -Rule </span><span style=”color: #800080;”>$Rule</span><span style=”color: #000000;”> -ManagementPack </span><span style=”color: #800080;”>$MPOverride</span><span style=”color: #000000;”>
}
}
Exit
}
</span><span style=”color: #0000ff;”>Else</span><span style=”color: #000000;”>
{
</span><span style=”color: #5f9ea0; font-weight: bold;”>Write-Host</span> <span style=”color: #800000;”>””</span>
<span style=”color: #5f9ea0; font-weight: bold;”>Write-Host</span> <span style=”color: #800000;”>”</span><span style=”color: #800000;”>User aborted process</span><span style=”color: #800000;”>”</span>
<span style=”color: #5f9ea0; font-weight: bold;”>Write-Host</span> <span style=”color: #800000;”>””</span>
<span style=”color: #5f9ea0;”>pause</span><span style=”color: #000000;”>
Exit
}
</span></pre>