It is already set LucD ( I borrowed your code with a few minor modifications - thanks !).
The firewall exception is added at the bottom. Please comment on what I'm missing and if this is sufficient to set up SNMP to a fully functional state
Clear
$esxName = Read-Host "Name of ESX Server"
$esxImpl = Get-VMHost -Name $esxName
$trapDestination = Read-Host "SNMP Management Server ?"
$trapCommunity = Read-Host "Community String ?"
# Connect to the ESX server
$esxConnect = Connect-VIServer -Server $esxName -Credential (Get-Credential)
# Get snmp object
$snmpObj = Get-VMHostSnmp -Server $defaultViServer
# Clear snmp configuration
Set-VMHostSnmp -HostSnmp $snmpObj -ReadOnlyCommunity @() -RemoveTarget -TrapTargetToRemove $snmpObj.TrapTargets[0]
# Enable snmp
Set-VMHostSnmp -HostSnmp $snmpObj -Enabled:$true
# Set read-only community
Set-VMHostSnmp -HostSnmp $snmpObj -ReadOnlyCommunity $trapCommunity
# Define trap target
Set-VMHostSnmp -HostSnmp $snmpObj -AddTarget -TargetCommunity $trapCommunity -TargetPort '162' -TargetHost $trapDestination
# Test snmp
Test-VMHostSnmp -HostSnmp $snmpObj
#Enable Firewall Rule
Get-VMHostFirewallException | ?{$_.Name.StartsWith('SNMP')} | Set-VMHostFirewallException -Enabled $true
#Start SNMP HERE ????? SNMPD Service shows STOPPED on the server......
# Disconnect from ESX server
Disconnect-VIServer -Server $esxConnect -Confirm:$false