Quantcast
Channel: VMware Communities : All Content - All Communities
Viewing all articles
Browse latest Browse all 207710

Set SNMP thru PowerCLI

$
0
0

Hi,

 

I want to set the SNMP parameters on a ESX host thru PowerCLI. Problem is that it generates an error on the last line.

 

Error:

Exception calling "ReconfigureSnmpAgent" with "1" argument(s): "A general syste

m error occurred: Set one community string or trap target for agent to listen o

n first."

At line:1 char:33

+ $SNMPsystem.ReconfigureSnmpAgent <<<< ($SNMPconfig)

    + CategoryInfo          : NotSpecified: ( [], MethodInvocationException

    + FullyQualifiedErrorId : DotNetMethodException

 

The script:

$ESXConnect=Connect-VIServer -Server "srv-esxi01.mydomain.local"

$ESXHost=Get-VMHost -Name "srv-esxi01.mydomain.local"

$SNMPhs = Get-View $ESXHost.ID

$SNMPsys = $SNMPhs.ConfigManager.SNMPSystem

$SNMPsystem = Get-View $SNMPhs.ConfigManager.SNMPSystem

$SNMPconfig = New-Object VMWare.Vim.HostSnmpConfigSpec

$SNMPtrapHost = New-Object vmware.Vim.HostSnmpDestination

$SNMPtrapHost.hostName = "1.1.1.1"

$SNMPtrapHost.community = "public"

$SNMPtrapHost.port = 162

$SNMPconfig.readOnlyCommunities = "ReadOnly"

$SNMPconfig.trapTargets = $SNMPtrapHost

$SNMPconfig.Enabled = 1

$SNMPsystem.ReconfigureSnmpAgent($SNMPconfig)

$SNMPsystem.SendTestNotification

 

I think i'm setting al the correct mandatory properties. But i'm lost. Any help is very welcome!

 

Regards,

 

Bastiaan


Viewing all articles
Browse latest Browse all 207710

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>