PowerShell – Configuring SNMP for ESXi Host

I have recently updated one of my scripts to configure the public community string and start up the SNMPD service for the ESXi host in my environment.  I also updated the script to work with my multitreaded script at the same time.

[int]$AllowedDifference = 1


Add-PSSnapin VMware.VimAutomation.Core

If (-not ($vmhost -or $vmhostlist))
$vmhosts = $Env:vmhostNAME

If ($vmhost)
$vmhosts = $vmhost

If ($vmhostlist)
$vmhosts = Get-Content $vmhostlist
foreach ($vmhost in $vmhosts) {

#Connect to ESXi host
Connect-VIServer -Server $vmhost -user root -password PASSWORD –ErrorAction Stop -WarningAction SilentlyContinue
catch {
write-host "Error authenticating to host "$vmhost

$serverlist = $global:DefaultVIServer

if($serverlist -ne $null) {
#Add SNMP Settings
Get-VMHostSnmp | Set-VMHostSnmp -Enabled:$true -ReadOnlyCommunity 'public'

$objSNMP = get-vmhostservice -VMHost $vmhost| where {$_.Key -eq "snmpd"}

#Start SNMP service
$objSNMP | start-VMhostservice

#configure Auto start and stop with host
$objSNMP | set-VMhostservice -Policy "On"

# Disconnect from vCenter
Disconnect-VIServer * -Confirm:$false




Leave a Reply

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