The below script may help you.
Check the following before executing the script :
1. The "servers.txt" file path is correct
2. Each server name in the "servers.txt" file should be in a new line.
Script :
$esx_list = Get-Content -Path "C:\scritp\servers.txt"
foreach ($item in $esx_list) {
Connect-VIServer -Server $item -User root -Password "password"
Get-VMHostSnmp | Set-VMHostSnmp -Enabled:$true -ReadOnlyCommunity "Name" -TargetHost "xxxxx"
}
Disconnect-VIServer * -Confirm:$false