Friday, February 24, 2012

[OpsMgr 2007] Export all performances rules by using a PowerShell Script

Here is a new PowerShell script usefull to list in a CSV file all performance rules in your management group - The script use a get-rules with a criteria "Category='PerformanceCollection'". Be carefull also when you developp some MPs to well categorize the rules.

$perf_collection_rules = get-rule -criteria:"Category='PerformanceCollection'"

4 functions are needed for filtering the result :

function GetPerfCounterName ([String] $configuration) {
          $config = [xml] ("<config>" + $configuration + "</config>")
          return ($config.Config.ObjectName + "\" + $config.Config.CounterName)
}


function GetFrequency ([String] $configuration) {
          $config = [xml] ("<config>" + $configuration + "</config>")
          $frequency = $config.Config.Frequency;
          if($frequency -eq $null) {
                    $frequency = $config.Config.IntervalSeconds;
          }
          return ($frequency)
}


function GetDisplayName($performanceRule) {
          if($performanceRule.DisplayName -eq $null) {
                      return ($performanceRule.Name);
           }
          else {
                      return ($performanceRule.DisplayName);
           }
}


function GetWriteActionNames($performanceRule) {
          $writeActions = "";
          foreach($writeAction in $performanceRule.WriteActionCollection) {
                     $writeActions += " " + $writeAction.Name;
           }
           return ($writeActions);
}

You are now able to export the $perf_collection_rules in a CSV file by getting the type, the rule display name, the counter name, the frequency and the write actions.

$perf_collection_rules | select-object @{name="Type";expression={foreach-object {(Get-MonitoringClass -id:$_.Target.Id).DisplayName}}},@{name="RuleDisplayName";expression={foreach-object {GetDisplayName $_}}} ,@{name="CounterName";expression={foreach-object {GetPerfCounterName $_.DataSourceCollection[0].Configuration}}},@{name="Frequency";expression={foreach-object {GetFrequency $_.DataSourceCollection[0].Configuration}}},@{name="WriteActions";expression={foreach-object {GetWriteActionNames $_}}}  | sort Type,RuleDisplayName,CounterName | export-csv "C:\perf_collection_rules.csv" -noTypeInformation


 I don't remember having developped this script by myself - perhaps it was not mine. By the way, this is very usefull.

>>>>>>>>>> Get the PS1 file Here <<<<<<<<<<

This posting is provided "AS IS" with no warranties.

No comments:

Post a Comment