Do you mean an Alarm?
What do you already have?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
And what is the code you used to create that Alarm?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
i didn't use powercli code . i configured from vsphere appliance only
The SMTP Alarm action does not give you access to the Username.
Only these fields.
You could consider running a script to gather that information, compose the email and send it.
But that would require an elaborate setup since you should not run scripts on your VCSA.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
okay . i tryed to run this but i got error .
$cluster = Get-Cluster -Name "ClusterName"
$vms = Get-VM -Location $cluster
New-AlarmDefinition -Name "Cluster VM Powered Off" -Entity $cluster -TriggerStatus "Red" -TriggerType "SpecificEvent" -TriggerEvent "PoweredOff"
$alarm = Get-AlarmDefinition -Name "Cluster VM Powered Off"
New-Alarm -AlarmDefinition $alarm -Name "Cluster VM Powered Off Alarm"
$email = New-AlarmAction -Email -To "admin@example.com" -Subject "Cluster VM Powered Off" -Body "A VM in the cluster has been powered off."
Set-Alarm -Alarm $alarm -Action $email
Enable-Alarm -Alarm $alarm
erorr getting :
New-AlarmDefinition : A parameter cannot be found that matches parameter name 'TriggerStatus'.
At line:1 char:54
+ ... armDefinition -Name "" -Entity $cluster -TriggerStatus "Red" - ...
+ ~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [New-AlarmDefinition], ParameterBindingException
+ FullyQualifiedErrorId : Name
New-Alarm -AlarmDefinition $alarm -Name "Cluster VM Powered Off Alarm"
New-Alarm : The term 'New-Alarm' is not recognized as the name of a cmdlet, function, script file, or operable
program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1
$email = New-AlarmAction -Email -To "" -Subject "Cluster VM Powered Off" -Body "A VM in the cluster has been powered off."
Set-Alarm : The term 'Set-Alarm' is not recognized as the name of a cmdlet, function, script file, or operable
program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1
+ Set-Alarm -Alarm $alarm -Action $email
+ ~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (Set-Alarm:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
Try like this.
Note: the Alarm is created "disabled", change as you like
$clusterName = 'ClusterName'
$to = 'admin@example.com'
$entity = Get-Cluster -Name $clusterName
$sTrigger = @{
EventType = Get-EventType | where{$_.Key -eq 'vmPoweredOffEvent'}
EntityStatus = 'Red'
EntityType = 'VirtualMachine'
}
$trigger = New-AlarmTrigger @sTrigger
$sAction = @{
Email = $true
Subject = 'VM Powered Off'
To = $to
Body = '{Target Name} is Powered Off'
}
$action =New-AlarmAction
$sAlarm = @{
Name = 'Test VM Powered Off 2'
Description = 'Send email when a VM is powered off'
Disabled = $true
AlarmTrigger = $trigger
AlarmAction = $action
Entity = $entity
Confirm = $false
}
New-AlarmDefinition @sAlarm
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference