Ever wanted an easy way to export a certain number of alerts (depending on the search criteria) for use later? Well, Operations Manager 2007 gives us that power using its Powershell provider. To use this functionality, you will need to use the Command Shell that is group with Operations Manager 2007 in the Start Menu. You can also invoke Command Shell from within the UI through the Monitoring Pane
Well, to get a list of all alerts from your management group, just run the following command:
PS Monitoring:\NOCRMS01.noc.momresources.org > Get-Alert
This will bring back a list of all alerts for the Management group that NOCRMS01 is a part of.
If your environmnt is large, you may want to filer your results by using the cmdlet Where-Object (also known as Where). Here is an example of all alerts in a Severity State of Warning and a Resolution of New:
> get-alert | where {$_.Severity -eq “Warning” -and $_.ResolutionState -eq 0 }
Now lets say you want to save the alerts from the previous example into an HTML file for easy viewing.. Here is the set of commands you can do to achieve that:
> $alert = get-alert | where {$_.Severity -ge “Warning” -and $_.ResolutionState -eq 0 }
> $alert | ConvertTo-Html | set-content c:\test.html
Or you can type it all in 1 line:
> get-alert | where {$_.Severity -eq “Warning” -and $_.ResolutionState -eq 0 } | ConvertTo-Html | set-content c:\test.html
This will convert the data from $alert variable into HTML (using the ConvertTo-HTML cmdlet) and then write the data to test.html located on the root of C:.
You can also get the alert history from the previous example and output that to HTML by running the following commands:
> $alert = get-alert | where {$_.Severity -eq “Warning” -and $_.ResolutionState -eq 0 }
> $alert | get-alerthistory | ConvertTo-Html | set-content c:\test2.html
Or
> get-alert | where {$_.Severity -eq “Warning” -and $_.ResolutionState -eq 0 } | ConvertTo-Html | set-content c:\test2.html
This the same export process as from the previous example except that we are saving the file to test2.html.
The final touch will be closing the same alerts we were searching for in the previous examples. If you wanted to, you can run this command with multiple pipe statements to pass the object from one command to another but it will look confusing so I am passing the results into variables.
> $alert | resolve-alert -comment: “Resolved by Powershell”
This all for now but as I learn more and find interesting statements, I will pass them on. In the meantime, check out the System Center Command Shell blog located at http://blogs.msdn.com/scshell/. There are awesome examples of using the OpsMgr 2007 Powershell provider.