10 Useful SCOM PowerShell Scripts

System Center Operations Manager (SCOM) comes with a good PowerShell module, there are many occasions where you want something done quick and easy.

There are a total of 183 different PowerShell cmdlets in the SCOM 2019 PowerShell module, that already speaks for itself how much you can do with this PowerShell module!

This blog post will provide an example for most commands, if you do not see the examples clearly, it's suggested you open the GIF in another browser tab.

Note: Some of the SCOM PowerShell cmdlets below are not found in the Microsoft documentation page for the System Center PowerShell 2016, these scripts have been tested to work with the following SCOM versions: 2016, 1801, 1807 and 2019.

Contents

  • Exporting sealed management packs

  • Exporting unsealed management packs

  • Setting a windows computer into maintenance mode

  • Retrieve the maintenance mode history for a windows computer

  • Enable the proxy for all SCOM agents

  • Retrieve all SCOM agents that are grayed out or unavailable

  • Retrieve all the SCOM alerts within the last day (highest priority first)

  • Retrieve all the subscriptions that a specific subscriber belongs to

  • Export all the SCOM agents to a CSV

  • Retrieve the amount of agents reporting to a SCOM Management / Gateway Server

Exporting sealed management packs

Get-SCOMManagementPack | where {$_.Sealed -eq $True } | Export-SCOMManagementpack -Path "C:\Management Packs\Sealed"

Example:

Exporting unsealed management packs

Get-SCOMManagementPack | where {$_.Sealed -eq $False} | Export-SCOMManagementpack -Path "C:\Management Packs\Unsealed"

Example:

Setting a windows computer into maintenance mode

$Agent = "yourcomputer.domain.com" $Time = (Get-Date).addMinutes(60) $Instance = (Get-SCOMClass -DisplayName "Windows Computer" | Get-SCOMClassInstance | ? { $_.DisplayName -eq $Agent} ) Start-SCOMMaintenanceMode -Instance $Instance -EndTime $Time -Comment "Maintenance Mode started!" -Reason "PlannedOther"

Example:

Retrieve the maintenance mode history for a windows computer

Get-SCOMMaintenanceMode -Instance (Get-SCOMClassInstance -Class (Get-SCOMClass -Name "Microsoft.Windows.Computer") | Where-Object {$_.DisplayName -match "Your Computer Name"}) -History -ErrorAction SilentlyContinue

Example:


Enable the proxy for all SCOM agents

Get-SCOMAgent | where {$_.ProxyingEnabled -match "False"} | Enable-SCOMAgentProxy

Retrieve all SCOM agents that are grayed out or unavailable

$Agent = Get-SCOMClass -Name "Microsoft.SystemCenter.Agent" $GrayAgents = Get-SCOMMonitoringObject -class $Agent | where {$_.IsAvailable –eq $False} $GrayAgents

Example:

Retrieve all the SCOM alerts within the last day (highest priority first)

$Date = (Get-Date).AddDays(-1) (Get-SCOMAlert -Criteria 'ResolutionState = "0"' | Where-Object {$_.LastModified -gt $Date }) | Sort-Object Priority -Descending

Resolution States

0 = New

255 = Closed

Severity Values for Alerts

0 = Informational

1 = Warning

2 = Critical

Example:


Retrieve all the subscriptions that a specific subscriber belongs to

Get-SCOMNotificationSubscription | ForEach { $Subscriber = $_.DisplayName $_.ToRecipients | foreach { If ($_.Name -Like "*Enter Name Here*") { Write-Host $Subscriber } } }

Example:

Export all the SCOM agents to a CSV

Get-SCOMAgent | Select DisplayName, ManagementGroup, Version, ProxyingEnabled | Export-Csv -NoType C:\SCOMAgents.csv

Example:

Retrieve the amount of agents reporting to a SCOM Management / Gateway Server

$MgmtServer = Get-SCOMManagementServer | where { $_.DisplayName -eq "yourSCOMmanagementserver.domain.com" } $TotalAgents = (Get-SCOMAgent -ManagementServer $MgmtServer).count $TotalAgents

Example:

Note: If you need to retrieve the amount of agents that are reporting to a SCOM Gateway server, change the DisplayName to the SCOM Gateway server name (without FQDN).

Previous
Previous

System Center 2019 is now generally available!

Next
Next

SCOM 2019 offers new experience for alerts generated by monitors