Blog
By Pete Zerger on 8/24/2010 5:54:56 AM • Rank (1933) • Views 2064
1

1

We were recently have a discussion in the SCC forums about some missing documentation around a particular OpsMgr PowerShell cmdlet when the discussion came 'round to how to output overrides in a readable format with all the relevant info. The main item missing is the source rule or monitor that the override targets.

As it turns out, Daniele Muscetta (a well-known Microsoft PFE) has already written a script that does most of the hard work to export the unsealed management pack and then retrieve the overrides in a readable format. The need came out in our forum discussion for a means to get the output into a single report file. All that was required were some simple changes to 1) add the name of the source management pack to a report column and 2) output the report to a single file instead of one for each management pack.

So I started with Daniele's script here -

Command Shell: Dumping all overrides in Operations Manager 2007 (Script)

Here are the changes I made:

  • Added logic to store the output of all the packs in a single variable 
  • Added the -notypeinfo flag to rid the output of the type info line on each pass, which is garbage for our purposes
  • Added an extra column to include the name of the management pack the override is stored in
  • Moved the override name to the far right column. The name string is so long and unruly it clutters the report

And here's the result. Many thanks to Daniele for this and the many other amazing contributions to the OpsMgr community over the past 3 years.

Sample Script

Here is a copy of the updated script. Make sure to replace the $exportpath variable with the name of an existing directory.

# ==============================================================================================
# 
# NAME: OpsMgr Overrides Report 
# 
# AUTHOR: Daniele Muscetta and Pete Zerger
# DATE  : 8/24/2010
# 
# 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"
 
#define the path you want to export the CSV files to
$exportpath = "c:\scripts\export\"
 
#gets all UNSEALED MAnagement PAcks
$mps = get-managementpack | where {$_.Sealed -eq $false}
 
#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 | get-override
 
    #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-MonitoringObject -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
 
}
    #exports cumulative list of overrides to a single CSV
 
    $filename = $exportpath + "overrides.csv"
    $MPRpt | Export-CSV -path $filename -notypeinfo
 
 

 

You can find all sorts of PowerShell scripts for System Center products at PowerShell Scripts for System Center (Master Collection) or in our Downloads section.

Follow System Center Central via Twitter and RSS

Twitter_icon rss_big_default_300x300

Comments - Comment RSS


Who Viewed
Who Reviewed
Categories
Related Pages
Shortened URL
http://tinyurl.com/27nxrdu

Top Contributors
Featured Members
Pete Zerger
Points: 65622
Level: System Center Expert
Tommy Gunn
Points: 42748
Level: System Center Expert
Simon Skinner
Points: 40804
Level: System Center Expert
Stefan Koell
Points: 28999
Level: System Center Expert
Andreas Zuckerhut
Points: 27734
Level: System Center Expert