SCOM 2012 Export Overrides Powershell Script

Standard

Today I was looking for a PowerShell script which can export all overrides based of a specific Management Pack. I found a script of Daniele Muscetta and Pete Zerger from SystemCenterCentral. This script did not worked out of the box on SCOM 2012 so I fixed that and added ‘HTML’ as output option. So with my addition it can be used on SCOM 2012 environments and the output can be a csv or html file.

The usage is:

.\Export-Overrides.ps1 -MS << Management Server >> –MP_Name << Displayname of MP >> -Output <<CSV or HTML >>

Be aware that you need to change the $exportpath variable in the script!  Please test this script first in your test environments, if you have any questions please let me know!

# ==============================================================================================
#
# NAME: OpsMgr Overrides Report
#
# ORGINAL AUTHOR: Daniele Muscetta and Pete Zerger
# ORGINAL DATE : 8/24/2010
#
# EDITED BY: Arjan Vroege
# EDITED DATA : 1/24/2014
#
# COMMENT: This report will output the overrides in your OpsMgr environment including
# override settings, target, source rule/monitor and source management pack.
# ==============================================================================================
#---Save the following text as script "Export-Overrides.ps1"

#Parameters
Param(
   [Parameter(Mandatory=$true)] [string]$MS,
   [Parameter(Mandatory=$true)] [string]$MP_Name,
   [Parameter(Mandatory=$true)] [string]$output
)

#Connect to SCOM Environment
Import-Module OperationsManager
New-SCOMManagementGroupConnection -ComputerName $MS

#define the path you want to export the CSV files to
$exportpath = ""
$MPRpt = $null
$MPRows = $null 

#gets all UNSEALED MAnagement PAcks
$mps = Get-SCOMManagementpack | where {$_.DisplayName -eq $MP_Name}

#loops thru them
foreach ($mp in $mps) {
    $mpname = $mp.name
    Write-Host "Exporting Overrides info for Managemetn Pack: $mpname"

    #array to hold all overrides for this MP
    $MPRows = @()

    #Gets the actual override objects
    $overrides = $mp.GetOverrides()

    #loops thru those overrides in order to extract information from them
    foreach ($override in $overrides) {
        #Prepares an object to hold the result
        $obj = new-object System.Management.Automation.PSObject

        #clear up variables from previous cycles.
        $overrideName = $null
        $overrideProperty = $null
        $overrideValue = $null
        $overrideContext = $null
        $overrideContextInstance = $null
        $overrideRuleMonitor = $null

        #give proper values to variables for this cycle. this is what we can then output.
        $name = $mp.name
        $overrideName = $override.Name
        $overrideProperty = $override.Property
        $overrideValue = $override.Value

        trap { $overrideContext = ""; continue } $overrideContext = $override.Context.GetElement().DisplayName
        trap { $overrideContextInstance = ""; continue } $overrideContextInstance = (Get-SCOMClassInstance -Id $override.ContextInstance).DisplayName

        if ($override.Monitor -ne $null) {
            $overrideRuleMonitor = $override.Monitor.GetElement().DisplayName
        } elseif ($override.Discovery -ne $null) {
            $overrideRuleMonitor = $override.Discovery.GetElement().DisplayName
        } else {
            $overrideRuleMonitor = $override.Rule.GetElement().DisplayName
        }

        #fills the current object with those properties

        #$obj = $obj | add-member -membertype NoteProperty -name overrideName -value $overrideName -passthru
        $obj = $obj | add-member -membertype NoteProperty -name overrideProperty -value $overrideProperty -passthru
        $obj = $obj | add-member -membertype NoteProperty -name overrideValue -value $overrideValue -passthru
        $obj = $obj | add-member -membertype NoteProperty -name overrideContext -value $overrideContext -passthru
        $obj = $obj | add-member -membertype NoteProperty -name overrideContextInstance -value $overrideContextInstance -passthru
        $obj = $obj | add-member -membertype NoteProperty -name overrideRuleMonitor -value $overrideRuleMonitor -passthru
        $obj = $obj | add-member -membertype NoteProperty -name MPName -value $name -passthru
        $obj = $obj | add-member -membertype NoteProperty -name overrideName -value $overrideName -passthru

        #adds this current override to the array
        $MPRows = $MPRows + $obj
    }

    #Store up the overrides for all packs to a single variable
    $MPRpt = $MPRpt + $MPRows
}

if($output -eq "csv") {
    #exports cumulative list of overrides to a single CSV
    $filename = $exportpath + "overrides" + $mp.name +".csv"
    $MPRpt | Export-CSV -path $filename -notypeinfo
} elseif ($output -eq "html") {
    $filename = $exportpath + "overrides" + $mp.name +".htm"
    $MPRpt | ConvertTo-Html | Out-File $filename
}

Credits and thnx to Daniele Muscetta and Pete Zerger

7 thoughts on “SCOM 2012 Export Overrides Powershell Script

  1. hi there just thought i would let you know that in your script it references get-monitoringobject this changed in 2012 to Get-SCOMClassInstance.

    i couldnt get your script to actually create the output file – so any input there would be great. It says its exporting but doesnt, picks up the mp id fine.

    • Arjan Vroege

      Thanks for the tip, I changed the script to only use the SCOM 2012 commands.
      Do you receive a error?

      Let me know, I’m happy to assist you to make this script working for you.

      Regards, Arjan

  2. Karan Bhalla

    Great script. Thank you for this.

    Just a quick note that the variables $MPRpt and MPRows don’t reset if this script is run multiple times in the same powershell session. Declaring them as $null in the beginning of the script worked like a charm.

    Cheers!

    Karan

  3. Chris

    added a few things to list parameters as well as properties, I believe no individual override would have both:
    $overrideParameter = $null

    $overrideParameter = $override.Parameter

    if ($overrideProperty -ne $null){$obj = $obj | add-member -membertype NoteProperty -name overrideParameter -value $overrideProperty -passthru}

    if ($overrideParameter -ne $null){$obj = $obj | add-member -membertype NoteProperty -name overrideParameter -value $overrideParameter -passthru}

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.