Showing posts with label CSV. Show all posts
Showing posts with label CSV. Show all posts

Thursday, January 31, 2013

[OpsMgr 2012][Powershell] Get Alerts for all specified SCOM MP using powershell in Operations Manager 2012


Here is a short powershell script I've just updated to be usable in operations Manager 2012 since cmdlet have been renamed. This script will help you to retrieve alerts from a specified SCOM MP using powershell.
 

Note that previous version dedicated to Operations Manager 2007 R2 is here
  
Here is the new script :

  1. $mp = Get-SCOMManagementPack -name 'MPName'
  2. # Criteria       : All alerts, raw and processed descriptions.
  3. # Output to      : File (c:\temp\output\Alerts-all.csv)
  4. # Fields Selected: Lots.
  5. # Output Format  : CSV
  6. # Notes          : Need more work on this.
  7. $alerts_csv = "C:\MPName.csv";
  8. write-host "Exporting all alerts to csv: ",$alerts_csv;
  9. Get-SCOMAlert | select-object @{Name = '%'; expression ={$_.MonitoringObjectDisplayName}},Severity, Name, ResolutionState, RepeatCount,@{Name = 'Instances'; expression ={$_.RepeatCount+1}},@{Name = 'Created'; expression =
  10. {$_.TimeRaised.ToLocalTime()}},@{Name = 'Description (Processed)';Expression = {$_.Description  -replace "`n"," " -replace " "," "}},MonitoringObjectFullName, IsMonitorAlert,Id,MonitoringRuleId,MonitoringClassId,Description | sort Name | export-csv $alerts_csv -noTypeInformation;
 Replace MPName in red by the your MP Name. Il will export all alerts in a CSV file.

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

Thursday, May 24, 2012

[OpsMgr 2007R2] Get member of all SCOM groups and export result in CSV files - Powershell script

Here is a script that will help you to create a CSV file per SCOM group. Each CSV file will have the name of the SCOM group and will contain this information
  • Name
  • Path
  • DisplayName
  • FullName
  • IsManaged
  • LastModified
  • HealthState
  • StateLastModified
  • IsAvailable
  • AvailabilityLastModified
  • InMaintenanceMode
  • MaintenanceModeLastModified
  • MonitoringClassIds
  • LeastDerivedNonAbstractMonitoringClassId
  • Id
  • ManagementGroup
  • ManagementGroupId
Empty group does not create a CSV file.

  1. function GetDisplayName($object){
  2.      $displayName = [System.String]::Empty
  3.      if(($object.DisplayName -eq $null) -or ($object.DisplayName.Length -eq 0)){
  4.            $displayName = $object.Name;
  5.      }
  6.      else {
  7.            $displayName = $object.DisplayName;
  8.      }
  9.      $displayName;
  10. }
  11. $mg = (Get-ManagementGroupConnection).ManagementGroup
  12. $groups = $mg.GetRootPartialMonitoringObjectGroups() | sort DisplayName
  13. foreach($group in $groups) {
  14.      Write-Host
  15.      Write-Host $group.DisplayName
  16.      $groupMembers = $group.GetRelatedPartialMonitoringObjects([Microsoft.EnterpriseManagement.Common.TraversalDepth]::OneLevel);
  17.      if($groupMembers.Count -eq 0) {
  18.            Write-Host "The group is empty"
  19.      }
  20.      else {
  21.             $groupMembers | Select-Object DisplayName,Path,@{name="Type";expression={foreach-object {GetDisplayName $_.GetLeastDerivedNonAbstractMonitoringClass()}}} | sort DisplayName | ft
  22.             $FileName = $group.DisplayName
  23.             $FileName += ".csv"
  24.             $OutPath = $FileName
  25.             $groupMembers | Export-Csv -Path $OutPath -NoTypeInformation
  26.      }
  27. Write-Host
  28. }

How to use it :
- First connect to you management group
  1. add-pssnapin "Microsoft.EnterpriseManagement.OperationsManager.Client";
  2. set-location "OperationsManagerMonitoring::";
  3. new-managementGroupConnection -ConnectionString:MyRMS.MyDomain -Credential (get-credential "Domain\Account");
 - secondly, set your location where you want to store the created CVS files :
  1. set-location c:\temp
- Then execute the script :



Result will be :
 And you will retrieve your files in the location you have set - in my case :



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

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.

Friday, January 13, 2012

[OpsMgr 2007 R2][Powershell] Get Alerts for all specified SCOM MP using powershell in Operation Manager 2007 R2

Here is a short powershell script you can use to retrieve alerts froml a specified SCOM MP using powershell.

  1. $mp = Get-ManagementPack -name 'MPName'
  2. # Criteria       : All alerts, raw and processed descriptions.
  3. # Output to      : File (c:\temp\output\Alerts-all.csv)
  4. # Fields Selected: Lots.
  5. # Output Format  : CSV
  6. # Notes          : Need more work on this.
  7. $alerts_csv = "C:\MPName.csv";
  8. write-host "Exporting all alerts to csv: ",$alerts_csv;
  9. Get-Alert | select-object @{Name = '%'; expression ={$_.MonitoringObjectDisplayName}},Severity, Name, ResolutionState, RepeatCount,@{Name = 'Instances'; expression ={$_.RepeatCount+1}},@{Name = 'Created'; expression =
  10. {$_.TimeRaised.ToLocalTime()}},@{Name = 'Description (Processed)';Expression = {$_.Description  -replace "`n"," " -replace " "," "}},MonitoringObjectFullName, IsMonitorAlert,Id,MonitoringRuleId,MonitoringClassId,Description | sort Name | export-csv $alerts_csv -noTypeInformation;
 Replace MPName in red by the your MP Name. Il will export all alerts in a CSV file.



An updated version for Operations Manager 2012 has been published >>>>>>>>>> here <<<<<<<<<<

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

[Powershell] Get Rules information or Monitors information for all MP in SCOM

Here is a short powershell command to list in a .CSV file Rules information for all SCOM MP using a powershell script :

Get Rules Informations :
  1. get-rule | select-object @{Name="MP";Expression={ foreach-object {$_.GetManagementPack().DisplayName }}}, @{Name="MP Version";Expression={ foreach-object {$_.GetManagementPack().Version }}}, Name, DisplayName, XmlTag, Enabled, Category |
    sort-object -property MP | export-csv "C:\Allrules-MyMgtGroupName.csv"
Get Monitors Informations :
  1. get-monitor | select-object @{Name="MP";Expression={ foreach-object {$_.GetManagementPack().DisplayName }}}, @{Name="MP Version";Expression={ foreach-object {$_.GetManagementPack().Version }}}, Name, DisplayName, XmlTag, Enabled, Category, Configuration  | Sort-object -property MP | export-csv "C:\AllMonitors-MyMgtGroupName.csv"
 With the same way, you can imagine listing all classes for all MP : see http://tetris38.blogspot.com/2012/01/powershell-get-classes-information-for.html

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

[Powershell] Get classes information for all MP in SCOM

Here is a short powershell command to list in a .CSV file all classes information for all SCOM MP using a powershell script :

  1. get-monitoringclass | select-object @{Name="MP";Expression={ foreach-object {$_.GetManagementPack().DisplayName }}}, @{Name="MP Version";Expression={ foreach-object {$_.GetManagementPack().Version }}}, Name, DisplayName, Id, Abstract, Accessibility, Base, Comment, Description, Hosted, LanguageCode, LastModified, ManagementGroup, ManagementGroupId, PropertyCollection, Singleton, Status, TimeAdded, XmlTag  |  sort-object -property MP | export-csv "C:\AllClasses-MyMgtGroupName.csv"

In my case this is usefull to determine what are the Name + ID for all classes for a specific MP to configure monitoring instructions in a tool.

With the same way you can export Rules and Monitors information for all your MP : http://tetris38.blogspot.com/2012/01/powershell-get-rules-information-or.html

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