Export overrides to CSV, XML & HTML
To accomplish an internal goal, this script has been updated to accept parameters.
New version is available here and can be used like this Export-Overrides -managementserver -path -type -suffix
**
Originally, this script was published by Daniele Muscetta and Pete Zerger over at SystemCenterCentral.com. I adopted Dieter Wijckmans version to fit our needs.
Basicly we all need to find our way to document how our OpsMgr environment is configured. We all have our ways (some not) and we first started out using exporting our MP’s to excel with MPViewer where we manually added colours to rules that where disabled. That worked good for us, and we still use this method when we import management packs the first time, but maintaining these documents can be tough. For some time i have exported all unsealed management packs used for overrides to .csv files, and used those to track changes. Today i was asked if i could make them easier to read. Therefor i took the script we have been using (credits in top post) and modified it to include XML, CSV and HTML exports. With the HTML we are able to easily read the overrides, we can use CSV to edit in excel and XML export (you all know this) can be imported back to OpsMgr in case you need it.
In order to get this script running. You have to set your export path, enable or disable export types and define a suffix for your overrides management pack. All this is done in the “configuration area”
#==================================================================================================================== # AUTHOR: DieterWijckmans (Dieter -Wijckmans -inovativ - be) # DATE: 03/08/2012 # Name: Export-Overrides2012.PS1 # Version: 1.2 # # MODIFIED BY: MartinEhrnst (m a r t i n - e h r n s t - n o) # MODIFY DATE: 18/03/2015 # # COMMENT: Export all your overrides to a CSV, XML & HTML files to keep for your reference. # Based on script of DanieleMuscetta and PeteZerger # http://www.systemcentercentral.com/BlogDetails/tabid/143/IndexID/78323/Default.aspx # # # Usage: Change your Management pack suffix, export location and Export types YES/NO. # Run script manually or with you favorite automation tool #DontHassleTheCode # #===================================================================================================================== ############################################################# ################# CONFIGURATION AREA ######################## #Set export location $locationroot = "PATH" #Define your Overrides suffix $MPSuffix = "SUFFIX" #export methods $CSV = "NO" #CSV export to use in excel etc. $HTML = "YES" #HTML for easier readability $XML = "YES" #enable if you want to import back toOpsMgr ################ END CONFIGURATION AREA ###################### ############################################################## #HTML OUTPUT STYLING $Header = @""@ ##This will read out your server name. Run from a management server. $objCompSys = Get-WmiObject win32_computersystem $inputScomMS = $objCompSys.name #Initializing the Ops Mgr 2012 Powershell provider# Import-Module -Name "OperationsManager" New-SCManagementGroupConnection -ComputerName $inputScomMS #Error handling setup $error.clear() $erroractionpreference = "SilentlyContinue" $thisScript = $myInvocation.MyCommand.Path $scriptRoot = Split-Path(Resolve-Path $thisScript) $errorLogFile = Join-Path $scriptRoot "error.log" if (Test-Path $errorLogFile) {Remove-Item $errorLogFile -Force} #Define the backup location #Get date $Backupdatetemp = Get-Date $Backupdatetemplocal = ($Backupdatetemp).tolocaltime() $Backupdate = $Backupdatetemplocal.ToShortDateString() $strBackupdate = $Backupdate.ToString() #Define backup location if((test-path $locationroot) -eq $false) { mkdir $locationroot } $locationfolder = $strbackupdate -Replace "/","-" $location = $locationroot + $locationfolder + "\" new-item "$location" -type directory -force #Delete backup location older than 15 days #To make sure our disk will not be cluttered with old backups we'll keep 15 days of backup locations. $Retentionperiod = "15" $folders = dir $locationroot echo $folders $now = [System.DateTime]::Now $old = $now.AddDays("-$Retentionperiod") foreach($folder in $folders) { if($folder.CreationTime -lt $old) { Remove-Item $folder.FullName -recurse } } #gets all UNSEALED MAnagement Packs with your defined suffix $mps = get-SCOMmanagementpack | where {$_.Sealed -eq $false -and $_.DisplayName -like "*$MPsuffix"} #loops thru them foreach ($mp in $mps) { $mpname = $mp.name Write-Host "Exporting Overrides info for Management 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. $overrideName = $override.Name $overrideProperty = $override.Property $overrideValue = $override.Value trap { $overrideContext = ""; continue } $overrideContext = $override.Context.GetElement().DisplayName trap { $overrideContextInstance = ""; continue } $overrideContextInstance = (Get-SCOMMonitoringObject -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 #adds this current override to the array $MPRows = $MPRows + $obj } #FILE EXPORT - SEE CONFIGURATION AREA #CSV if ($csv -eq "YES"){ $filename = $location + $mp.name + ".csv" $MPRows | Export-Csv $filename } #XML see configuration if ($XML -eq "YES"){ Export-SCOMManagementPack -ManagementPack $mps -Path $location } #HTML see configuration $filename = $location + $mp.name + ".html" if ($HTML -eq "YES"){ $MPRows | ConvertTo-Html -Title "Overrides For $mp" -Head $Header | Out-File $filename } }