Command Shell Reference

Find Rule/monitor by ID

get-monitoringobject -id

To find a rule. get-rule -id (GUID)

Return a full list of classes

Get-MonitoringClass | Select DisplayName,Same | Sort DisplayName

Return License Expiration

Get-SCOMManagementGroup | ft skuforlicense, version, timeofexpiration –a

Export overrides for a Management Pack

get-override -managementPack name.mp | export-csv filename

Export Mangement Packs Sealed or Unsealed

get-managementpack |where {$_.Sealed -eq $false} |Export-ManagementPack -path ?:\directory\

Just change the false to true for sealed.

Find Management Pack of Specific Name

$mp=Get-ManagementPack|Where {$_.Name -eq “your_valid_MP_name”}

Find Management Pack of  Name Like

Get-ManagementPack|Where {$_.Name -like “*DPM*”}|Select Name

What are the Gateway Servers Failover set to

Get-GatewayManagementServer | where {$_.Name -like 'MGT01.domain.com'} | Get-PrimaryManagementServer
Get-GatewayManagementServer | where {$_.Name -like 'MGT01.domain.com'} | Get-FailoverManagementServer

Change the Gateway Servers Failover settings

$primaryMS = Get-ManagementServer | where {$_.Name -eq ‘mgt01.testdomain.local’}
$failoverMS = Get-ManagementServer | where {$_.Name -eq ‘mgt02.testdomain.local’}
$gatewayMS = Get-GatewayManagementServer | where {$_.Name -eq ‘gw01.nontrustdomain.local’}
Set-ManagementServer -GatewayManagementServer: $gatewayMS -primarymanagementserver: $primaryMS -FailoverServer: $failoverMS

WARNING: There are a couple of Gotchas when changing the GW  failover settings that can result in a unmanageable GW. This is because when we run the set commands the management server gets the update and it stops accepting connections from your gateway server That could result in an orphaned gateway as the gateway server is not allowed to communicate with any management server.

This is a known issue and there many scripts in the community to resolve this.

http://contoso.se/blog/?p=831

http://www.vnext.be/2010/12/08/scom-gateway-primary-and-failover-ms/

Display a list of outputs for a management pack’s monitors and overrides using the command shell,

get-monitor -managementPack name.mp | export-csv filename

eg: get-monitor -managementPack System.Health.Library.mp | export-csv “C:\monitors.csv”

Display overrides for a management pack

get-override -managementPack name.mp | export-csv filename

eg: get-override -managementPack Microsoft.SystemCenter.OperationsManager.Internal.mp | export-csv “c:\overrides.csv”

Display management pack rules

get-rule | select-object @{Name=”MP”;Expression={ foreach-object {$_.GetManagementPack().DisplayName }}},DisplayName | sort-object -property MP | export-csv “c:\rules.csv”

Display monitor thresholds, use the script described in this section. This script works for the majority of monitors. It creates a .csv file that includes the following columns and that can be viewed using Excel.

Column Description
Type The type of objects the monitor is targeted to
DisplayName The display name of the monitor
Threshold The threshold used by the monitor
AlertOnState Determines whether the monitor generates an alert when the state changes
AutoResolveAlert Determines whether the generated alert will be automatically resolved when the monitor state goes back to green
AlertSeverity The severity of the generated alert

Run the following script to create the .csv file that displays the monitor thresholds:

function GetThreshold ([String] $configuration)

{

$config = [xml] (“<config>” + $configuration + “</config>”)

$threshold = $config.Config.Threshold

if($threshold -eq $null)

{

$threshold = $config.Config.MemoryThreshold

}

if($threshold -eq $null)

{

$threshold = $config.Config.CPUPercentageThreshold

}

if($threshold -eq $null)

{

if($config.Config.Threshold1 -ne $null -and $config.Config.Threshold2 -ne $null)

{

$threshold = “first threshold is: ” + $config.Config.Threshold1 + ” second threshold is: ” + $config.Config.Threshold2

}

}

if($threshold -eq $null)

{

if($config.Config.ThresholdWarnSec -ne $null -and $config.Config.ThresholdErrorSec -ne $null)

{

$threshold = “warning threshold is: ” + $config.Config.ThresholdWarnSec + ” error threshold is: ” + $config.Config.ThresholdErrorSec

}

}

if($threshold -eq $null)

{

if($config.Config.LearningAndBaseliningSettings -ne $null)

{

$threshold = “no threshold (baseline monitor)”

}

}

return $threshold

}

$perfMonitors = get-monitor -Criteria:”IsUnitMonitor=1 and Category=’PerformanceHealth'”

$perfMonitors | select-object @{name=”Target”;expression={foreach-object {(Get-MonitoringClass -Id:$_.Target.Id).DisplayName}}},DisplayName, @{name=”Threshold”;expression={foreach-object {GetThreshold $_.Configuration}}}, @{name=”AlertOnState”;expression={foreach-object {$_.AlertSettings.AlertOnState}}}, @{name=”AutoResolveAlert”;expression={foreach-object {$_.AlertSettings.AutoResolve}}}, @{name=”AlertSeverity”;expression={foreach-object {$_.AlertSettings.AlertSeverity}}} | sort Target, DisplayName | export-csv “c:\monitor_thresholds.csv”

Display performance collection rules, use the script in this section. This script works for the majority of monitors. It creates a .csv file that includes the following columns and that can be viewed using Excel.

Column Description
WriteAction Contains information about where the performance counter is written
WriteToDB or CollectionPerformanceData Writes to the Operations Manager Operations database
WriteToDW or CollectPerfDataWarehouse Writes to the data warehouse
WC Stores baseline data for a performance counter in the Operations Manager Operations database

To display the performance collection rules present in the management group, run the following script:

function GetPerfCounterName ([String] $configuration)

{

$config = [xml] (“<config>” + $configuration + “</config>”)

return ($config.Config.ObjectName + “\” + $config.Config.CounterName)

}

function GetFrequency ([String] $configuration)

{

$config = [xml] (“<config>” + $configuration + “</config>”)

$frequency = $config.Config.Frequency;

if($frequency -eq $null)

{

$frequency = $config.Config.IntervalSeconds;

}

return ($frequency)

}

function GetDisplayName($performanceRule)

{

if($performanceRule.DisplayName -eq $null)

{

return ($performanceRule.Name);

}

else

{

return ($performanceRule.DisplayName);

}

}

function GetWriteActionNames($performanceRule)

{

$writeActions = “”;

foreach($writeAction in $performanceRule.WriteActionCollection)

{

$writeActions += ” ” + $writeAction.Name;

}

return ($writeActions);

}

$perf_collection_rules = get-rule -criteria:”Category=’PerformanceCollection'”

$perf_collection_rules | select-object @{name=”Type”;expression={foreach-object {(Get-MonitoringClass -id:$_.Target.Id).DisplayName}}},@{name=”RuleDisplayName”;expression={foreach-object {GetDisplayName $_}}} ,@{name=”CounterName”;expression={foreach-object {GetPerfCounterName $_.DataSourceCollection[0].Configuration}}},@{name=”Frequency”;expression={foreach-object {GetFrequency $_.DataSourceCollection[0].Configuration}}},@{name=”WriteActions”;expression={foreach-object {GetWriteActionNames $_}}}  | sort Type,RuleDisplayName,CounterName | export-csv “c:\perf_collection_rules.csv”

Advertisements
This entry was posted in Command Shell - Powershell Reference. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s