Report vSphere Alarms with Powershell

Wow, vSphere vCenter Server has a lot of new alarms! Great for monitoring your environment. But a pain when it comes to documenting it. Thank God VMware for the PowerCLI! Just a few lines of code can do the documentation for you.

Here’s how:

# Report vSphere Alarms
# by Hugo Peeters
#Region Variables
$VCServer = "myVCServer"
$Outfile = "D:\scripts\Alarms.txt"
Connect-VIServer $VCServer
$SI = Get-View ServiceInstance
$AM = Get-View $SI.Content.AlarmManager
$myCol = @()
ForEach ($Folder in (Get-Folder))
	ForEach ($Alarm in ($AM.GetAlarm(($Folder|Get-View).MoRef)))
		$Alarm = Get-View $Alarm
		$myObj = "" | Select Folder, Name, Description, Enabled, Summary
		$myObj.Folder = $Folder.Name
		$myObj.Name = $Alarm.Info.Name
		$myObj.Description = $Alarm.Info.Description
		$myObj.Enabled = $Alarm.Info.Enabled
		$myObj.Summary = $Alarm.Info.Expression.Expression | Out-String
		$myCol += $myObj
$myCol | Where {$_.Enabled} | Out-File $Outfile
ii $Outfile


6 thoughts on “Report vSphere Alarms with Powershell”

  1. Had to modify this slightly to get it to work on my system. Added the Server parameter to Get-folder like so Get-folder -Server $VCServer

Leave a Reply