Export Overrides to CSV

Export Overrides to readable CSV.

I have modified Daniele Muscetta and Pete Zerger’s script located here.

http://systemcentercentral.com/BlogDetails/tabid/143/IndexID/78323/Default.aspx
Copy between the lines and save to PS1.

#################################################

# NAME: OpsMgr Overrides Report

# COMMENT: This report will output the overrides in your OpsMgr environment including

# override settings, target, source rule/monitor and source management pack.

# ==============================================================================================

# — VARiabless—

# RMS Name
$RMS=”RMSName HERE”

# — SETTING UP OPS COMMAND SHELL —

if ((Get-PSSnapin | Where-Object {$_.Name -eq ‘Microsoft.EnterpriseManagement.OperationsManager.Client’}) -eq $null) {
Add-PSSnapin Microsoft.EnterpriseManagement.OperationsManager.Client -ErrorAction SilentlyContinue -ErrorVariable Err
if ($Err) { $(throw write-Host $Err) }
}
if ((Get-ManagementGroupConnection | Where-Object {$_.ManagementServerName -eq $RMS}) -eq $null) {
Write-Host “Connecting to Management Server: $RMS”
New-ManagementGroupConnection $RMS -ErrorAction SilentlyContinue -ErrorVariable Err |out-null
if ($Err) { $(throw write-Host $Err) }
}
if ((Get-PSDrive | Where-Object {$_.Name -eq ‘Monitoring’}) -eq $null) {
New-PSDrive -Name: Monitoring -PSProvider: OperationsManagerMonitoring -Root: \ -ErrorAction SilentlyContinue -ErrorVariable Err|out-null
if ($Err) { $(throw write-Host $Err) }
Write-Host “Operations manager shell initialized.”
}

Set-Location Monitoring:\$RMS |out-null

# — define the path you want to export the CSV to —

$exportpath = “D:\Script\Exportoverride.ps1”

#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

##############################################

Copy the exportoverride.ps1 script to directory of your choosing.

Open the Run command Script execut powershell script.

Advertisements
This entry was posted in Command Shell - Powershell Reference, Uncategorized. 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