Resetting Logical Disk Fragmentation Monitor via PowerShell

I’ve been goog..errr bing’ing trying to look for a solution and most everyone points to the GreenMachine. Although a great and powerful tool that I have used on occasion, for some reason it does not filter for monitors in “Warning” only state and I cannot filter by monitor. In this case I will be resetting healthstate for monitors I did not intent to. I have assignee and ticket number assigned to the associated alert. If the monitor resets I lose that tracking information. My goal is to reset healthstate for only the “Logical Disk Fragmentation” monitors. There are two of these monitors, one for Windows 2003 and one for Windows 2008. My proposed solution is to utilize PowerShell with the SCOM snapin. Next week when my fragmentation monitors flip back to “Warning” state I will try the PS script I created and post an update. In theory it should work 😀
Sponsors, article continues below...

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
# ==============================================================================================
#
# AUTHOR: Stephen - http://www.blogmynog.com
# DATE  : 12/08/2010
#
# COMMENT: Resets health state for the "Logical Disk Fragmentation Level" monitor for Windows 2003
#		and 2008 LogicalDisk classes. You may need to sign this PowerShell script
#		(Get-Help About_Signing) or change your execution policy (Get-Help Set-ExecutionPolicy)
#		in order to run it in your environment. Great for throwing into task scheduler!
# ==============================================================================================
 
#Usage: ResetFragmentationHealth.ps1 -rmsServerName:'rms01'
 
param($rmsServerName)
 
Add-PSSnapin "Microsoft.EnterpriseManagement.OperationsManager.Client";
Set-Location "OperationsManagerMonitoring::";
$mgConn = New-ManagementGroupConnection -connectionString:$rmsServerName
Set-Location $rmsServerName
 
# Windows 2003
$mon = get-monitor | where {$_.Name -eq 'Microsoft.Windows.Server.2003.LogicalDisk.DefragAnalysis'}
$mc = get-monitoringClass -name Microsoft.Windows.Server.2003.LogicalDisk
$mc | get-monitoringObject | where {$_.HealthState -eq 'Warning' -or $_.HealthState -eq 'Error'} | foreach {$_.ResetMonitoringState($mon)}
 
# Windows 2008
$mon = get-monitor | where {$_.Name -eq 'Microsoft.Windows.Server.2008.LogicalDisk.DefragAnalysis'}
$mc = get-monitoringClass -name Microsoft.Windows.Server.2008.LogicalDisk
$mc | get-monitoringObject | where {$_.HealthState -eq 'Warning' -or $_.HealthState -eq 'Error'} | foreach {$_.ResetMonitoringState($mon)}
 
# End
This entry was posted in Microsoft, SCOM.

Leave a Reply