VMware documentation is excellent, but not if you're a beginner with PowerCLI. While you will find documentation on how to configure SNMP for your ESXi hosts, the way it's presented is not very clear and will leave you scratching your head in confusion since you'll be thinking how does this configure SNMP on all my ESXi hosts?
Simple Network Management Protocol (SNMP) is used to manage and monitor network devices and their functions by setting up a community string using version 1 or 2 or using version 3, which adds both encryption and authentication. The script discussed here will use either version 1 or 2, but not 3.
Warning! If you have monitoring software, be aware that if you have SNMP already running and are updating the community string and restart the service, you'll get a false alert that the ESXi host has rebooted. If you're part of a large team, seeing alerts that an ESXi host has rebooted can send some people into a panic, unless of course you already know that maintenance is going on. Make sure to let your teammates know you are changing SNMP settings.
Assumption(s) made: You have a working vCenter Server, you have PowerCLI installed and are connected to vCenter Server via PowerCLI. Additionally, you have credentials for both vCenter Server and the root password for ESXi. You are configuring SNMP for version 1 or 2 using the script below.
If you're ready to setup SNMP for you ESXi hosts, let's get started.
The script below will allow you to multi-select the ESXi hosts you want to configure, and then will set the SNMP community string to your desired value and either start or restart the SNMP service.
The first section of the script is just the title, the version, and comments on what the script does and is very much self-explanatory.
$vcenter = Read-Host -Prompt "Enter your vCenter Server name (FQDN)"
$vcenterCred = Get-Credential -Message "Enter your vCenter Server Credentials"
$esxiCred = Get-Credential -Message "Enter your ESXi root credentials"
The thirds section, titled "Connect to vCenter" does just that: connects to your vCenter Server.
In first line, you are setting some configuration options before connecting to vCenter Server such as ignoring any invalid certificates. I do this because it's very common to find many deployments that don't have properly deployed certificates. Also, because we will not only connect to vCenter Server but your ESXi hosts directly, we don't want any warnings about connecting to multiple servers
Byron Zepeda is a Senior Systems Engineer in Orange County, California, working with VMware vSphere, Citrix Virtual Apps, backups, and storage. As cloud technologies and automation become first-class citizens within IT organizations, he desires to share everything he learns and pass it on to others.