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.

2 comments:

  1. Hello I'm getting error message when trying to run the script above. Error message "Get-Managment pack is not valid cmdlet.

    ReplyDelete
    Replies
    1. Hello, did you connect your environement before using the script ? I mean did you use :
      # Load OpsMgr envir...
      if ( (Get-pssnapin | where {$_.Name -eq "Microsoft.EnterpriseManagement.OperationsManager.Client" }).Name -ne "Microsoft.EnterpriseManagement.OperationsManager.Client" ) {
      add-pssnapin "Microsoft.EnterpriseManagement.OperationsManager.Client" -ErrorVariable errSnapin; }

      $RMS = "MyRMS"
      $creds = Get-Credential("MyDomain\MyAccount");
      $connection = New-ManagementGroupConnection -ConnectionString: $RMS -Credential: $creds #-ErrorAction:SilentlyContinue;
      #New-PSDrive -Name OpsMgr -PSProvider OperationsManagerMonitoring -Root \ -Scope: Global
      # Move off of a drive to avoid deadlock.
      Set-Location "OperationsManagerMonitoring::" | Out-Null;

      If yes, are you using Operations Manager 2007 R2 or 2012 ?

      If you use Operations Manager 2007 R2 : use the Get-ManagementPack cmdlet
      (http://technet.microsoft.com/en-us/library/gg132230.aspx)

      If you use Operations Manager 2012, replace Get-ManagementPack cmdlet by Get-SCOMManagementPack (http://technet.microsoft.com/en-us/library/hh918497.aspx)
      And Get-Alert cmdlet by Get-SCOMAlert... hope I don't miss anything.



      Check new post here : http://tetris38.blogspot.fr/2013/01/opsmgr-2012powershell-get-alerts-for.html

      Delete