Created
October 10, 2016 20:40
-
-
Save 1RedOne/7aa2c1d827506bb9b4c0aa06529e9923 to your computer and use it in GitHub Desktop.
Added a paramset to make the cmdlet easier to use, defaults to localhost now and provides feedback if can't connect
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ============================================================================================== | |
# | |
# 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=$env:computername, | |
[Parameter(Mandatory=$true)] [string]$MP_Name, | |
[Parameter(Mandatory=$true)][ValidateSet("html", "csv")] [string]$output | |
) | |
#Connect to SCOM Environment | |
Import-Module OperationsManager | |
Write-host "Trying to connect to SCOM SDK Service on $MS" | |
try {New-SCOMManagementGroupConnection -ComputerName $MS -errorAction STOP} | |
catch{Write-Warning "Failed to connect to SCOM SDK Service on $MS" | |
Write-Warning "Please validate service is running or provide correct Management Server name as -MS" | |
return} | |
#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() | |
"found $($overrides.count) Overrides" | |
#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 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment