RSGs “One-Liners”

This page features some of MY most used one-liners. It could be SQL queries, Powershell scripts or any other SCOM related one-liner.

All of these scripts have been tested in a production environment, but please test it before using any of them.


(Powershell)

Close all alerts from rules XX hours old (can be changed in the script)

Import-module OperationsManager
$connect = New-SCOMManagementGroupConnection –ComputerName localhost
$AgeHours = 48
get-scomalert -criteria ‘ResolutionState=”0” AND IsMonitorAlert=”False”’ |where {$_.LastModified -le (Get-Date).addhours(-$AgeHours)} | resolve-SCOMAlert -Comment ‘Auto closed by script’ -PassThru | Set-SCOMAlert -ResolutionState 255


(Powershell)

List all SCOM objects in Maintenance Mode on a single server (run from server)

$server = (Get-WmiObject win32_computersystem).DNSHostName + “.” + (Get-WmiObject win32_computersystem).Domain
Get-SCOMMonitoringObject | where-object {$_.InMaintenanceMode -eq $true} | where-object {$_.DisplayName -eq $server}


(Powershell)

List all SCOM objects in Maintenance Mode

Get-SCOMMonitoringObject | where-object {$_.InMaintenanceMode -eq $true}


(SQL Query)

Set all SCOM agents to Remote Manageable

UPDATE MT_HealthService
SET IsManuallyInstalled=0
WHERE IsManuallyInstalled=1


(Powershell)

List all alerts generated by a rule

get-scomalert -criteria ‘ResolutionState = ”0”’ | where-object {($_.IsMonitorAlert -eq $False)}

Advertisements