Configuring SNMP on multiple ESXi hosts

While talking with my colleague from the networking department, it seemed nice to have our ESXi NICs in Cacti for performance/load logging and troubleshooting.
As apposed to me complaining about a slow network, he can now complain about NIC utilization at my desk =)

Configuring the necessary SNMP parameters for each ESXi host can be a time consuming task.
The PowerCLI command used for this (Set-VMHostSnmp) does not support connecting to vCenter and configuring multiple hosts at one time.

Because of this I created a script which configures these parameters on multiple ESXi hosts, including separate user accounts, passwords and SNMP community strings. I made use of a foreach loop and each host configured in the config.txt file will run through the same set of commands:

Connect to ESXi host
Configure SNMP (Enable and configure SNMP string)
Disconnect ESXi host

For this, the script consists of two files: the script itself and a config.txt file where you can input multiple hosts in CSV format.

Use the script at your own risk! I have used it in my test environment and will try the script tomorrow in our acceptation and production environment.

The script files can be downloaded from here.

Let me know if you have any improvements or want to share your experience with the script!

#General information
#Date: April 24nd, 2013
#Author: Rene Bos
#Script version: 0.1

#Script summary
#This script is created for configuring SNMP on multiple ESXi 5.1 hosts using PowerCLI so your monitoring tool can request SNMP information.
#The environment I had to configure this in, used different root passwords for each ESXi host and required a different approach which resulted in this script.
#Use the supplied config.txt file to enter ESXi hostnames, passwords and SNMP community strings before running the script.
#Each line in this file represents one ESXi host.

#Please use this script at your own risk and test it out in your testlab first before using it in production
#When using my script, please leave the general information in place. And let me know if my scripts needs improvement!

$caption = "This script assumes you have yet filled in the required fiels in the 'config.txt' file."
$message = "Do you want to run this script now?"
$yes = New-Object System.Management.Automation.Host.ChoiceDescription "&Yes","This will run the script now based on the data in the config.txt file"
$no = New-Object System.Management.Automation.Host.ChoiceDescription "&No","Do not run this script now"
$choices = [System.Management.Automation.Host.ChoiceDescription[]]($yes,$no)
$answer = $host.ui.PromptForChoice($caption,$message,$choices,0)

switch ($answer)
    0 {"The script will execute NOW"; }
    1 {"The script will NOT execute"; Exit}

$ESXiHosts = Import-Csv "config.txt"
foreach ($ESXiHost in $ESXiHosts)
Connect-VIServer $ESXiHost.ESXi_Host -User $ESXiHost.Username -Password $ESXiHost.Password
Get-VMHostSnmp | Set-VMHostSnmp -Enabled:$True -ReadOnlyCommunity $ESXiHost.Snmp_String
Disconnect-VIServer -Server * -Force -Confirm:$False

2 thoughts on “Configuring SNMP on multiple ESXi hosts

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s