You can use the Set-VMHostSnmp cmdlet, but that requires you connect to the ESXi node (not the vCenter).
I find it easier to do this with esxcli and only connect to the vCenter.
Something like this for example
$esxName = 'MyEsx'$community = 'community1'
$esx = Get-VMHost -Name $esxName
$esxcli = Get-EsxCli -VMHost $esx -V2
$snmpGet = $esxcli.system.snmp.get.Invoke()
if($snmpGet.community -eq $null -or $snmpGet.communities.Split(',') -notcontains $community){
$snmpSet = @{
communities = if($snmpGet.communities -eq $null){$community}else{"$($snmpGet.communities -join ','),$community"}
}
$esxcli.system.snmp.set.Invoke($snmpSet)
}
Instead of doing this for 1 ESXi node, you can, of course, do this in a loop, and run the code for each ESXi node in for example a cluster.