Has been done before, but things have changed with 6.5 and Get-EsxCli -V2, so I thought I’d share an updated script.   This makes sure you have the same SNMP settings on all hosts.  This is kind of a response to comment on this page

Uses also the newer method of loading the VmWare PowerCLI modules.

#require -module VMware.VimAutomation.Core

$vcsa = "vcentre.yourdomain.local" # Your vSphere server
$snmpdROCommunities = "PuBl1c" # v2c RO comminuties (can comma seperated list of up to 10)
$syscontact = "administrator@vsphere.local" # Set the snmp attributes
$syslocation = "My DataCentre"
$port = "161" #Change the port if you want
$me = Get-Credential -Message "vSphere Admin"

Connect-VIServer -Server $vcsa -Credential $me | Out-Null

$vmhosts = Get-VMHost | where {$_.ConnectionState -eq "Connected"}
foreach ($vmhost in $vmhosts) {
  #Set SNMP settings using new V2 esxcli interface
  $esxcli = Get-EsxCli -VMHost $vmhost -V2
  $arguments = $esxcli.system.snmp.set.CreateArgs()
  $arguments.communities = $snmpdROCommunities
  $arguments.enable = $true
  $arguments.port = $port
  $arguments.syscontact = $syscontact
  $arguments.syslocation = $syslocation


  #Quickly dump out the new config
  write-host $vmhost.Name

  $snmpd = Get-VMHostService -VMHost $vmhost | where {$_.Key -eq "snmpd"}
  #Start SNMP service - if not configured properly it will error here
  $snmpd | start-VMhostservice
  #configure Auto start and stop with host
  $snmpd | set-VMhostservice -Policy "On"

Disconnect-VIServer -Server $vcsa
Setting SNMP on all ESXi 6.5 hosts in a cluster

4 thoughts on “Setting SNMP on all ESXi 6.5 hosts in a cluster

    • 2020-10-13 at 8:42 am

      Only if you want to reset the SNMP settings to factory default!

  • 2020-10-22 at 2:49 pm

    snmp target in not mentioned in that script

    • 2020-11-26 at 9:13 am

      That’s right. This is for SNMP get/set responses only. i.e active monitoring. SNMP target is only needed when you want the ESXi host to send traps to some monitoring host.


Leave a Reply

Your email address will not be published. Required fields are marked *