PowerCLI

Expand all | Collapse all

PowerCLI: Enable / Disable Alarm Actions on Hosts / Clusters

  • 1.  PowerCLI: Enable / Disable Alarm Actions on Hosts / Clusters

    Posted Jun 14, 2011 09:23 AM

    Hello All,

    I have done some serious googling, and am about to accept that it is not possible through PowerCLI.

    But I wanted to make a last effort by asking you guys.

    For ESXi host maintenance, I want to use a PowerCLI script which does this:

    1. - disable alarm actions on Cluster
    2. - disable alarm actions on Hosts

    3. - perform maintenance (can be anything, but will include host reboots)

    4. - enable alarm actions on Hosts
    5. - enable alarm actions on Cluster

    Because we have 300+ ESXi hosst, you can imagine I want to do this scripted.

    Is there any way to disable/enable alarm actions through PowerCLI ?

    Thanks and kind regards,

    Harold



  • 2.  RE: PowerCLI: Enable / Disable Alarm Actions on Hosts / Clusters

    Posted Jun 14, 2011 09:56 AM

    Did you try it this way

    $cluster = Get-Cluster MyCluster
    $alarm = Get-AlarmDefinition -Entity $cluster -Name "Just an alarm"
    Set-AlarmDefinition -AlarmDefinition $alarm -Enabled:$false


  • 3.  RE: PowerCLI: Enable / Disable Alarm Actions on Hosts / Clusters

    Posted Jun 14, 2011 10:17 AM

    Hi Luc,

    Thanks for taking a look at this.

    But this script would disable an alarm throughout the entire vcenter.

    Most important alarm I don't want to trigger alarm actions is: Host connection and power state

    This alarm is set and managed on the vcenter top level.

    During patching of one cluster, I still want to get alarms from other clusters/hosts.

    Regards,

    Harold



  • 4.  RE: PowerCLI: Enable / Disable Alarm Actions on Hosts / Clusters

    Posted Jun 14, 2011 11:50 AM

    That is just the principle behind the alarms; you define them on an entity and all child entities will inherit that alarm.

    Assume a datacenter with 3 clusters.

    You defined an alarm on the datacenter.

    If you want to disable that alarm on a specific cluster, without disabling it on the other clusters, you will have to define the alarm not on the datacenter but on each of the clusters individualy , I'm afraid.



  • 5.  RE: PowerCLI: Enable / Disable Alarm Actions on Hosts / Clusters

    Posted Jun 14, 2011 12:06 PM

    I was kinda afraid that was going to be the answer :smileysad:

    Within the vSphere Client I can right-click a host or cluster and select Alarms | Disable Alarm Actions

    I was hoping PowerCLI could do the same for me.

    I can see the PowerCLI property, but have no idea how to change these:

    [vSphere PowerCLI] D:\Scripts> $esxhost = get-vmhost myhost
    [vSphere PowerCLI] D:\Scripts> $esxhost.ExtensionData.AlarmActionsEnabled
    False

    [vSphere PowerCLI] D:\Scripts> $cluster = get-cluster mycluster
    [vSphere PowerCLI] D:\Scripts> $cluster.ExtensionData.AlarmActionsEnabled
    False

    Regards,
         Harold



  • 6.  RE: PowerCLI: Enable / Disable Alarm Actions on Hosts / Clusters
    Best Answer

    Posted Jun 14, 2011 12:17 PM

    Ok, it seems we were talking about two different things.

    What you want to do can be done from a PowerCLI script.

    Something like this

    $alarmMgr = Get-View AlarmManager 
    $cluster
    = Get-Cluster MyCluster
    #
    To disable alarm actions
    $alarmMgr
    .EnableAlarmActions($cluster.Extensiondata.MoRef,$false) # To enable alarm actions
    $alarmMgr
    .EnableAlarmActions($cluster.Extensiondata.MoRef,$true)

    The same can be done for an ESX(i) host

    $alarmMgr = Get-View AlarmManager
    $esx = Get-VMHost MyEsx

    # To disable alarm actions
    $alarmMgr.EnableAlarmActions($esx.Extensiondata.MoRef,$false) # To enable alarm actions
    $alarmMgr
    .EnableAlarmActions($esx.Extensiondata.MoRef,$true)

    Sorry about the confusion :smileyhappy:



  • 7.  RE: PowerCLI: Enable / Disable Alarm Actions on Hosts / Clusters

    Posted Jun 14, 2011 01:05 PM

    Luc,

    thanks a lot !

    This is exactly what I was looking for !

    Thanks again and best regards,

         Harold



  • 8.  RE: PowerCLI: Enable / Disable Alarm Actions on Hosts / Clusters

    Posted Jun 23, 2020 02:58 PM

    Hey LucD

    Are these commands still valid? Will they work with VMware PowerCLI 12.0.0 build 15947286, VCSA 6.7.0 15976728, VMware ESXi 6.7.0 build-15018017

    $alarmMgr = Get-View AlarmManager
    $cluster
    = Get-Cluster MyCluster
    #
    To disable alarm actions
    $alarmMgr
    .EnableAlarmActions($cluster.Extensiondata.MoRef,$false)

    # To enable alarm actions
    $alarmMgr
    .EnableAlarmActions($cluster.Extensiondata.MoRef,$true)

    The same can be done for an ESX(i) host

    $alarmMgr = Get-View AlarmManager
    $esx = Get-VMHost MyEsx

    # To disable alarm actions
    $alarmMgr.EnableAlarmActions($esx.Extensiondata.MoRef,$false)

    # To enable alarm actions
    $alarmMgr
    .EnableAlarmActions($esx.Extensiondata.MoRef,$true)


  • 9.  RE: PowerCLI: Enable / Disable Alarm Actions on Hosts / Clusters

    Posted Jun 23, 2020 03:01 PM

    Since then the cmdlets Get-AlarmDefinition and Set-AlarmDefinition were introduced.
    You can easily enable/disable an alarm with those cmdlets.



  • 10.  RE: PowerCLI: Enable / Disable Alarm Actions on Hosts / Clusters

    Posted Jun 23, 2020 03:44 PM

    Thanks  



  • 11.  RE: PowerCLI: Enable / Disable Alarm Actions on Hosts / Clusters

    Posted Jun 27, 2021 10:11 AM

    It is not working now in the new version PowerCli. I'm getting below error.

     

    Exception calling "EnableAlarmActions" with "2" argument(s): "The object 'vim.HostSystem:host-266712' has already been deleted or has not been completely created"
    At line:1 char:1
    + $alarmMgr.EnableAlarmActions($esx.Extensiondata.MoRef,$true)
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : VimException



  • 12.  RE: PowerCLI: Enable / Disable Alarm Actions on Hosts / Clusters

    Posted Oct 22, 2021 12:21 AM

    Same error here: "Exception calling "EnableAlarmActions" with "2" argument(s): "The object 'vim.HostSystem:host-102792' has already been deleted or has not been completely created"

    For an hour I've been trying to find a working method to disable alarm actions for all hosts in a cluster via PowerCLI.  I'm about to give up and just tell my colleagues to ignore the alarms.  Nothing works!



  • 13.  RE: PowerCLI: Enable / Disable Alarm Actions on Hosts / Clusters

    Posted Oct 22, 2021 06:26 AM

    Did you stop/start your PowerShell session in between tries?



  • 14.  RE: PowerCLI: Enable / Disable Alarm Actions on Hosts / Clusters

    Posted Oct 22, 2021 02:20 PM

    It works for a colleague.  I think my PowerShell is broken.

    167 ms | C:\Users\e12> Set-PSDebug -Trace 2
    9 ms | C:\Users\e12> $alarmMgr.EnableAlarmActions($esx.Extensiondata.MoRef,$false)
    DEBUG: 1+ >>>> $alarmMgr.EnableAlarmActions($esx.Extensiondata.MoRef,$false)
    DEBUG: ! CALL function '<ScriptBlock>'
    DEBUG: 19+ if ( & >>>> { Set-StrictMode -Version 1; $_.PSMessageDetails } ) {
    DEBUG: ! CALL function '<ScriptBlock>'
    DEBUG: 19+ if ( & { >>>> Set-StrictMode -Version 1; $_.PSMessageDetails } ) {
    DEBUG: 19+ if ( & { Set-StrictMode -Version 1; >>>> $_.PSMessageDetails } ) {
    DEBUG: 1+ & >>>> { Set-StrictMode -Version 1; $this.Exception.InnerException.PSMessageDetails }
    DEBUG: ! CALL function '<ScriptBlock>'
    DEBUG: 1+ & { >>>> Set-StrictMode -Version 1; $this.Exception.InnerException.PSMessageDetails }
    DEBUG: 1+ & { Set-StrictMode -Version 1; >>>> $this.Exception.InnerException.PSMessageDetails }
    DEBUG: 1+ & { Set-StrictMode -Version 1; $this.Exception.InnerException.PSMessageDetails >>>> }
    DEBUG: 19+ if ( & { Set-StrictMode -Version 1; $_.PSMessageDetails >>>> } ) {
    DEBUG: 26+ $errorCategoryMsg = & >>>> { Set-StrictMode -Version 1; $_.ErrorCategory_Message }
    DEBUG: ! CALL function '<ScriptBlock>'
    DEBUG: 26+ $errorCategoryMsg = & { >>>> Set-StrictMode -Version 1; $_.ErrorCategory_Message }
    DEBUG: 26+ $errorCategoryMsg = & { Set-StrictMode -Version 1; >>>> $_.ErrorCategory_Message }
    DEBUG: 26+ $errorCategoryMsg = & { Set-StrictMode -Version 1; $_.ErrorCategory_Message >>>> }
    DEBUG: 42+ $originInfo = & >>>> { Set-StrictMode -Version 1; $_.OriginInfo }
    DEBUG: ! CALL function '<ScriptBlock>'
    DEBUG: 42+ $originInfo = & { >>>> Set-StrictMode -Version 1; $_.OriginInfo }
    DEBUG: 42+ $originInfo = & { Set-StrictMode -Version 1; >>>> $_.OriginInfo }
    DEBUG: 42+ $originInfo = & { Set-StrictMode -Version 1; $_.OriginInfo >>>> }
    Exception calling "EnableAlarmActions" with "2" argument(s): "The object 'vim.HostSystem:host-83069' has already been deleted or has not been completely created"
    At line:1 char:1
    + $alarmMgr.EnableAlarmActions($esx.Extensiondata.MoRef,$false)
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : VimException



  • 15.  RE: PowerCLI: Enable / Disable Alarm Actions on Hosts / Clusters

    Posted Dec 29, 2022 04:30 PM

    Posting this in case it helps someone.

    I got this error as well. I think it was because in testing I had 2 connections to vcenter.

    When I used get-vmhost, I had double entries for each system.

    I disconnected my connections and tried again (commenting out my connect line after I entered my creds as I was debugging)

    I didn't see the error after that.



  • 16.  RE: PowerCLI: Enable / Disable Alarm Actions on Hosts / Clusters

    Posted Jan 17, 2023 09:03 AM

    Hi

    Is it possible to get the Alarms-Status for every element in vCenter: Clusters, Hosts, Vms, Datastore, Networks ?

    We hat the Alarms disabled for one Hosts, and for one Storage. The Infrastructure has 9 Hosts, 250 VMs, 30-40 NFS Datastores, and dSwitches. To check them manually...not a good idea

    Thanks



  • 17.  RE: PowerCLI: Enable / Disable Alarm Actions on Hosts / Clusters

    Posted Jan 17, 2023 09:23 AM

    Would this work for you?

    Get-AlarmDefinition |
    Select Name, @{N='Entity';E={$_.Entity.Name}},Enabled


  • 18.  RE: PowerCLI: Enable / Disable Alarm Actions on Hosts / Clusters

    Posted Jan 17, 2023 03:50 PM

    Hi.

    Thank you for the time.

    No. I can find this script output in the AlarmDefinition of the vCenter.

    What I need to see if any of the Hosts, VMs or Datastores have the option "Alarms -> Disable Alarm Actions" - from the Right click Menu - disabled.

    Have a nice day.

     



  • 19.  RE: PowerCLI: Enable / Disable Alarm Actions on Hosts / Clusters

    Posted Jan 17, 2023 06:15 PM

    You mean something like this?

    Get-Inventory |
    Select Name,
      @{N='Type';E={$_.GetType().Name.Replace('Impl','')}},
      @{N='AlarmActionsEnabled';E={$_.ExtensionData.AlarmActionsEnabled}}


  • 20.  RE: PowerCLI: Enable / Disable Alarm Actions on Hosts / Clusters

    Posted Jan 18, 2023 07:50 AM

    Hi

    Perfect.

    Together with the 

    Get-Datastore | Select Name, @{N='Type';E={$_.GetType().Name.Replace('Impl','')}}, @{N='AlarmActionsEnabled';E={$_.ExtensionData.AlarmActionsEnabled}}

    I have manage to find some VMs and some Storages that had the Alarms disabled.

    Thank you!



  • 21.  RE: PowerCLI: Enable / Disable Alarm Actions on Hosts / Clusters

    Posted Sep 01, 2023 01:08 PM

    Hi LucD,

    Sorry for awakening this old thread, but I had a related question:

    I suspect there are individual hosts in my environment which have the alarm actions disabled. Is there a simple way to get a list of all of them that are in this state?

    Thanks.



  • 22.  RE: PowerCLI: Enable / Disable Alarm Actions on Hosts / Clusters

    Posted Sep 01, 2023 02:06 PM

    Try something like this

    Get-VMHost |
    Where{-not $_.ExtensionData.AlarmActionsEnabled} |
    Select Name,
      @{N='AlarmActionsEnabled';E={$_.ExtensionData.AlarmActionsEnabled}}


  • 23.  RE: PowerCLI: Enable / Disable Alarm Actions on Hosts / Clusters

    Posted Sep 01, 2023 03:08 PM

    Thanks LucD!

    I did some testing and noticed that this only was showing hosts that had the setting, very simple to check the clusters using the same logic and just changing to get-cluster:

    Get-Cluster |
    Where{-not $_.ExtensionData.AlarmActionsEnabled} |
    Select Name,
      @{N='AlarmActionsEnabled';E={$_.ExtensionData.AlarmActionsEnabled}}

     



  • 24.  RE: PowerCLI: Enable / Disable Alarm Actions on Hosts / Clusters

    Posted Jun 03, 2013 07:50 AM

    Hi all,

    Is it possible only for one Virtual machine ?

    With the GUi is easy (right click on VM and disable) but in powershell is not really ....

    Many thanks



  • 25.  RE: PowerCLI: Enable / Disable Alarm Actions on Hosts / Clusters

    Posted Jun 03, 2013 09:06 AM

    With the functions I provided in Alarm actions – enable – disable – report you should be able to specify a VM.

    Something like this

    $vm = Get-VM MyVM
    $vm | Set-AlarmActionState -Enabled:$false


  • 26.  RE: PowerCLI: Enable / Disable Alarm Actions on Hosts / Clusters

    Posted Jun 03, 2013 09:53 AM

    Great, working fine !!!!!!

    Many Thanks



  • 27.  RE: PowerCLI: Enable / Disable Alarm Actions on Hosts / Clusters

    Posted Jan 31, 2025 11:39 AM

    Hi LucD

    How to apply this script on multiple VMs & Host? 




  • 28.  RE: PowerCLI: Enable / Disable Alarm Actions on Hosts / Clusters

    Posted Feb 01, 2018 02:58 PM

    this works great, but with the syntax presented, I can't figure out how to do multiple clusters at once, or the entire stack of hosts within vCenter.   Can you please update this post to show how I can run this and disable all hosts in a specific vcenter?   Otherwise, I would have to run this script against each cluster one by one... 



  • 29.  RE: PowerCLI: Enable / Disable Alarm Actions on Hosts / Clusters

    Posted Feb 01, 2018 04:54 PM

    Not sure i get your question 100%.
    Do you want to enable/disable a specific alarm action on all alarms on all VMs in all cluster under all vCenters?

    Are you working in single or multiple mode?



  • 30.  RE: PowerCLI: Enable / Disable Alarm Actions on Hosts / Clusters

    Posted Feb 01, 2018 06:20 PM

    I want to disable and the later re-enable Alarm actions on each host in the vCenter inventory, not within a single cluster.  Right click the host, you see alarms and from there disable or enable alarm actions.  If doing maintenance on a single host you would first disable alarm actions so that snmp traps don't get sent when the host is rebooted for example.  Then after maintenance you re-enable so that when a real issue occurrs the alarms can act and send the snmp traps. 

    See, VMware alerting is bugging, to say the least.  Some alarms, when you edit them, trigger actions (snmp traps) that go to our automation system and pages get sent.  So before I start editing any more alerts I want to be certain the no snmp traps are going to get sent.    the host connection and powerstate alert was sending too many false alerts, I opened it up to look at it, clicked ok when done, and boom snmp traps were sent by every host in vCenter to our automation system which then sent a bunch of emails and pages.  This happened 2x now, and I'm afraid to touch this alert again until each host has the alarm actions disabled so the traps aren't sent when configuring the alarms.     



  • 31.  RE: PowerCLI: Enable / Disable Alarm Actions on Hosts / Clusters

    Posted Feb 01, 2018 06:29 PM

    The following will for each connected vCenter, get all the ESXi nodes, and then for each ESXi disable Alarms.
    For the reverse you comment out the 'disable' line and uncomment the 'enable' line.

    foreach($vc in $global:DefaultVIServers){

        $alarmMgr = Get-View AlarmManager -Server $vc

        foreach($esx in Get-VMHost -Server $vc){

            # To disable alarm actions

            $alarmMgr.EnableAlarmActions($esx.Extensiondata.MoRef,$false)

           

            # To enable alarm actions

            #$alarmMgr.EnableAlarmActions($esx.Extensiondata.MoRef,$true)

        }

    }



  • 32.  RE: PowerCLI: Enable / Disable Alarm Actions on Hosts / Clusters

    Posted Feb 01, 2018 06:32 PM

    thank you sir - you are the man. 



  • 33.  RE: PowerCLI: Enable / Disable Alarm Actions on Hosts / Clusters

    Posted Nov 07, 2019 08:06 PM

    Thanks LucD, seems in 6.7 i'm having issues trying to find the view in html5 that shows you that satus of Host Alarms Enabled/Disabled?

    Can you elaborate on how one can do this with PowerCLI, just show an operator the status of alarms within a VC?

    TIA



  • 34.  RE: PowerCLI: Enable / Disable Alarm Actions on Hosts / Clusters

    Posted Nov 07, 2019 08:54 PM

    The Get-AlarmDefinition cmdlet has the Enabled property.



  • 35.  RE: PowerCLI: Enable / Disable Alarm Actions on Hosts / Clusters

    Posted Nov 07, 2019 09:21 PM

    I'm still a bit confused here.

    Im looking for a powerCLI solution, to not only Enable or Disable alarms, but one that would also just list the hosts and the status Enabled/Disabled (True or False) in the output letting me know if a have an unwanted host enabled or disabled.

    In the Thick client i swear there was a view that allowed you to see all the hosts and that status, however in HTML5 6.7 i'm just not seeing it anymore.



  • 36.  RE: PowerCLI: Enable / Disable Alarm Actions on Hosts / Clusters

    Posted Nov 07, 2019 09:46 PM

    You could do something like this

    Get-VMHost -PipelineVariable esx | Get-AlarmDefinition |

    Select @{N='VMHost';E={$esx.Name}},Enabled,Name

    And you can also see that in the Web Client