Hi
This wonderful script was created by LucD. The script creates a new alarm for the host. Does anyone know how to modify it so the script creates new alarm in vCenter level.
$esxName = 'hostname'
$alarmMgr = Get-View AlarmManager #only works when connect to vc not esx
$entity = Get-VMHost -Name $esxName | Get-View
# AlarmSpec
$alarm = New-Object VMware.Vim.AlarmSpec
$alarm.Name = "Host Alarm"
$alarm.Description = "Monitoring host"
$alarm.Enabled = $TRUE
#Action
$alarm.action = New-Object VMware.Vim.GroupAlarmAction
$trigger = New-Object VMware.Vim.AlarmTriggeringAction
$trigger.action = New-Object VMware.Vim.SendSNMPAction
# Transaction
$trans = New-Object VMware.Vim.AlarmTriggeringActionTransitionSpec
$trans.startstate = "yellow"
$trans.finalstate = "red"
$trans.repeats = $false
$trigger.transitionspecs += $trans
$alarm.action.action += $trigger
# Expression
$expression = New-Object VMware.Vim.EventAlarmExpression
$expression.EventType = "EnteringMaintenanceModeEvent"
$expression.ObjectType = "HostSystem"
$expression.Status = "red"
$alarm.expression = New-Object VMware.Vim.OrAlarmExpression
$alarm.expression.expression += $expression
$alarm.setting = New-Object VMware.Vim.AlarmSetting
$alarm.setting.reportingFrequency = 0
$alarm.setting.toleranceRange = 0
# Create alarm.
$alarmMgr.CreateAlarm($entity.MoRef, $alarm)