Skip to content

Instantly share code, notes, and snippets.

@starkfell
Created December 1, 2012 15:11
Show Gist options
  • Select an option

  • Save starkfell/4182813 to your computer and use it in GitHub Desktop.

Select an option

Save starkfell/4182813 to your computer and use it in GitHub Desktop.
SCOM 2012 - Agent Monitoring Query Tool (ManagementPacks,Monitors,Rules, and Overrides)
#################################################################################
#
# [SCOM_Mon_Query.ps1] - SCOM 2012 - Agent Monitoring Query Tool
#
# Author: Ryan Irujo
#
# Inception: 11.26.2012
# Last Modified: 11.30.2012
#
# Syntax: ./SCOM_Mon_Query.ps1 <hostname>
#
# Script is HEAVILY in progress....you have been warned.
#
#
#################################################################################
param($HostName)
Clear-Host
if($HostName -eq $null) {echo "Type in the Name of a Host!!!" ; exit 2}
#QUERY ORDER = Host THEN MPs THEN Monitors THEN Overrides THEN Whatever.....
$ErrArray = @()
$MPClassID_1 = @()
$MPFullName_1 = @()
$MPRules_1 = @()
# ----- Querying SCOM Monitoring Objects based on HostName. -----
$MonObjects = Get-SCOMMonitoringObject | Where-Object {$_.DisplayName -match "$($HostName)"}
ForEach ($MP in $MonObjects){
$MPClassID = $MP.get_LeastDerivedNonAbstractManagementPackClassId()
$MPFullNameQuery = $MP.get_FullName().ToString()
$MPFullNameTrim = $MPFullNameQuery.IndexOf(":")
$MPFullName = $MPFullNameQuery.Substring(0,$MPFullNameTrim)
$MPClassID_1 += "$($MPClassID)"
$MPFullName_1 += "$($MPFullName)"
echo "$($HostName) => MP Class IDs = $($MPClassID) => MPs = $($MPFullName)"
}
# ----- Querying SCOM Monitors based upon previously found Least Derived Non Abstract Management Pack Class ID. -----
ForEach ($GUID in $MPClassID_1){
$MP_Monitors = Get-SCOMMonitor | Where-Object {$_.Target -match $GUID }
Foreach ($Monitor in $MP_Monitors) {
$MPUniqueUIDQuery = $Monitor.get_Target().ToString()
$MPUniqueUIDTrim = $MPUniqueUIDQuery.IndexOf("=")
$MPUniqueUID = $MPUniqueUIDQuery.SubString($MPUniqueUIDTrim).Trim("=")
$MP_MonitorName = $Monitor.get_Name()
$Monitor_Enabled = $Monitor.get_Enabled()
$Monitor_Status = $Monitor.get_Status()
echo "MON:MP UID = $($MPUniqueUID) => Enabled? = $($Monitor_Enabled) FOR => $($MP_MonitorName)"
}
}
# ----- Quering SCOM Rules based upon previously found Least Derived Non Abstract Management Pack Class ID. Again.... -----
ForEach ($GUID in $MPClassID_1){
$MP_Rules = Get-SCOMRule | Where-Object {$_.Target -match $GUID }
try {
Foreach ($Rule in $MP_Rules) {
$MP_RuleTargetQuery = $Rule.get_Target().ToString()
$MP_RuleTargetTrim = $MP_RuleTargetQuery.IndexOf("=")
$MP_RuleTarget = $MP_RuleTargetQuery.SubString($MP_RuleTargetTrim).Trim("=")
$MP_RuleEnabled = $Rule.get_Enabled()
$MP_RuleDisplayName = $Rule.get_DisplayName()
echo "RULES:MP UID = $($MP_RuleTarget) => Enabled? = $($MP_RuleEnabled) FOR => $($MP_RuleDisplayName)"
}
}
catch {
if ([System.Management.Automation.RuntimeException]) {continue}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment