2016年4月18日 星期一

Export SCOM Overrides

## You’ll need to run the script from within a SCOM console or load the SCOM Powershell module.
#define the path you want to export the CSV files to
$exportpath = "c:\admin\"
 
#gets all UNSEALED MAnagement PAcks
$mps = get-managementpack | where {$_.displayname -eq "Overrides.Microsoft.Exchange.2010"}
 
#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.
         $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
 
        #adds this current override to the array
         $MPRows = $MPRows + $obj
     }
 
    #exports to CSV
     $filename = $exportpath + $mp.name + ".csv"
     $MPRows | Export-Csv $filename
}

沒有留言:

張貼留言