VMware Cloud Community
dscottimw
Enthusiast
Enthusiast
Jump to solution

Exception calling "EnableAlarmActions" with "2" argument(s):

Hi,

I am trying to write a script that gives me the option to enable/disable alarm actions on all my ESXi hosts attached to a particular virtual center. 

I've got the code mostly working but I'm getting this error when I execute the code"

Exception calling "EnableAlarmActions" with "2" argument(s): "

Required parameter entity is missing

while parsing call information for method EnableAlarmActions

at line 1, column 171

while parsing SOAP body

at line 1, column 64

while parsing SOAP envelope

at line 1, column 0

while parsing HTTP request for method setAlarmActionsEnabled

on object of type vim.alarm.AlarmManager

at line 1, column 0"

At \\fs-55-ah\vmgr$\home05\dscotti\Documents\Scripts\WIP\set esxi host alarm state.ps1:37 char:13

+             $alarmmgr.EnableAlarmActions($esx.ExtensionData.MoRef,$tr ...

+             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException

    + FullyQualifiedErrorId : VimException

My script is attached. Any thoughts on what I've got wrong would be much appreciated.

Thanks

Dan

Dan Scotti
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Try like this

# source the connect/disconnect functions

if ($PSVersionTable.OS -match 'Linux*') {

    Write-host $PSVersionTable.OS

    . "/home/Documents/Scripts/Working/connecttovcenter.ps1"

    . "/home/Documents/Scripts/Working/fn_disconnect.ps1"

    }

   else {

    . "\\home\Documents\Scripts\Working\connecttovcenter.ps1"

    . "\\home\Documents\Scripts\Working\fn_disconnect.ps1"

    }


Connecttovcenter


While(($answ = Read-Host 'Do you want to enable or disable the alarm state for ESXi hosts? (Enable/Disable)')-notmatch 'Enable$|Disable$'){}

$upansw = $answ.toupper()


$esxhost = @()

$data = @()


$alarmmgr = get-view AlarmManager


foreach ($esx in Get-vmhost) {


   # $output = ""| Select "EsxHost", "AlarmState"


   # $output.EsxHost = $esx

   # $output.AlarmState = $alarmEnabled

 

   $alarmEnabled = $esx.ExtensionData.AlarmActionsEnabled

 

   if ($alarmEnabled -eq "False" -and $upansw -eq 'ENABLE') {

 

   $alarmmgr.EnableAlarmActions($esx.ExtensionData.MoRef,$true)

 

   }


   if ($alarmEnabled -eq 'True' -and $upansw -eq 'DISABLE') {

 

   $alarmmgr.EnableAlarmActions($esx.ExtensionData.MoRef,$false)

 

   }

   }

## $data | Export-Csv -Path \\mathworks\home\dscotti\Documents\Scripts\WIP\alarmenableddisabled.csv -NoTypeInformation


disconnect


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

0 Kudos
3 Replies
dscottimw
Enthusiast
Enthusiast
Jump to solution

Also here is the powercli version I am using.

Get-PowerCLIVersion

PowerCLI Version

----------------

   VMware PowerCLI 6.5 Release 1 build 4624819

---------------

Component Versions

---------------

   VMware Cis Core PowerCLI Component 6.5 build 4624453

   VMware VimAutomation Core PowerCLI Component 6.5 build 4624450

   VMWare ImageBuilder PowerCLI Component 6.5 build 4561891

   VMWare AutoDeploy PowerCLI Component 6.5 build 4561891

   VMware Vds PowerCLI Component 6.5 build 4624695

   VMware Cloud PowerCLI Component 6.5 build 4624821

   VMware HA PowerCLI Component 6.0 build 4525225

   VMware HorizonView PowerCLI Component 7.0.2 build 4596620

   VMware Licensing PowerCLI Component 6.5 build 4624822

   VMware PCloud PowerCLI Component 6.5 build 4624825

   VMware Storage PowerCLI Component 6.5 build 4624820

   VMware vROps PowerCLI Component 6.5 build 4624824

   VMware vSphere Update Manager PowerCLI 6.5 build 4540462

My esx hosts are a variety of 6.0 flavors.

Dan Scotti
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Try like this

# source the connect/disconnect functions

if ($PSVersionTable.OS -match 'Linux*') {

    Write-host $PSVersionTable.OS

    . "/home/Documents/Scripts/Working/connecttovcenter.ps1"

    . "/home/Documents/Scripts/Working/fn_disconnect.ps1"

    }

   else {

    . "\\home\Documents\Scripts\Working\connecttovcenter.ps1"

    . "\\home\Documents\Scripts\Working\fn_disconnect.ps1"

    }


Connecttovcenter


While(($answ = Read-Host 'Do you want to enable or disable the alarm state for ESXi hosts? (Enable/Disable)')-notmatch 'Enable$|Disable$'){}

$upansw = $answ.toupper()


$esxhost = @()

$data = @()


$alarmmgr = get-view AlarmManager


foreach ($esx in Get-vmhost) {


   # $output = ""| Select "EsxHost", "AlarmState"


   # $output.EsxHost = $esx

   # $output.AlarmState = $alarmEnabled

 

   $alarmEnabled = $esx.ExtensionData.AlarmActionsEnabled

 

   if ($alarmEnabled -eq "False" -and $upansw -eq 'ENABLE') {

 

   $alarmmgr.EnableAlarmActions($esx.ExtensionData.MoRef,$true)

 

   }


   if ($alarmEnabled -eq 'True' -and $upansw -eq 'DISABLE') {

 

   $alarmmgr.EnableAlarmActions($esx.ExtensionData.MoRef,$false)

 

   }

   }

## $data | Export-Csv -Path \\mathworks\home\dscotti\Documents\Scripts\WIP\alarmenableddisabled.csv -NoTypeInformation


disconnect


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
dscottimw
Enthusiast
Enthusiast
Jump to solution

Thanks LucD.  I knew it was something stupid.

I also had to change the -eq to -like in this section :

  if ($alarmEnabled -eq "False" -and $upansw -eq 'ENABLE') {

   $alarmmgr.EnableAlarmActions($esx.ExtensionData.MoRef,$true)

   }

   if ($alarmEnabled -eq 'True' -and $upansw -eq 'DISABLE') {

   $alarmmgr.EnableAlarmActions($esx.ExtensionData.MoRef,$false)

Works like a charm now though. 

Dan Scotti
0 Kudos