Wednesday, 30 March 2011

3 useful SCOM powershell reports

Often one wants quick access to a list of agents in SCOM or perhaps a report of open alerts.


In our SCOM setup it takes what sometimes seems an eternity to open the console so here's a quicker way.


It's not very obvious with System Center Operations Manager / SCOM how to extract a list of agents so here are three useful powershell queries to export data with the first example being a list of agent objects with just key columns of data.
These examples make use of the Select-Object and Sort-Object commandlets


########### GET AGENTS / AGENT LIST#######################
# export a list of agents sorted by name and showing only key columns of data
$title="AgentList"
$Body = get-agent | select Name,DisplayName,PrimaryManagementServerName,HealthState,Domain,IPAddress,Version,InstallTime,InstalledBy,ProxyingEnabled | sort-object Name
$Body | ConvertTo-Html | set-content c:\temp\$Title.htm




############ OPEN Alerts ########################
# export a list of alerts sorted by LastmodifiedDate desc and showing only key columns
# do as csv because typically massive
$title="OpenAlertsByUTCDateModDesc"
$Body =get-alert -criteria 'ResolutionState = "0"' | select Id,Name,Priority,Severity,TimeRaised,LastModified,MonitoringObjectDisplayName,MonitoringObjectPath,Category,Description,MonitoringObjectId,MonitoringClassId,IsMonitorAlert | sort-object LastModified -descending
$body | Export-Csv c:\temp\$Title.csv




########## PENDING ACTIONS ##################
# export a list of pending actions (agents waiting to be approved in Pending management screen)
$title="PendingActions"
$Body = get-agentpendingaction | select agentname,AgentPendingActionType,ManagementServerName,LastModified | sort-object agentname
$Body | ConvertTo-Html | set-content c:\temp\$Title.htm