1 Reply Latest reply on Feb 12, 2018 9:55 PM by VMDonttouch

    Factory reset SNMP configuration with powerCLI

    GeraldBegin Lurker

      Hi guys,

       

           I need to factory reset the SNMP config on each HOSTs in the entire environment (over 400 hosts, ESXi 5.5 and 6.0)

           I need to do it true the vCenter credential because all HOST have a different password.

       

      Ex:

       

      ..........

      $vmhosts = @(Get-VMHost -location $clustername)

       

      foreach ($vmhost in $vmhosts) {

      Write-Host ‘$vmhost = ‘ $vmhost

      $esxcli = Get-EsxCli -VMHost $vmhost

       

      $esxcli.system.snmp.set ??    ###  I tested with -r, --reset, etc .. nothing works with commands used in SSH. I also tested with ($ null, $ null, $ null, $ null, .. for all parameters but without success).

       

      $esxcli.system.snmp.get()

       

       

      Disconnect-VIServer * -Confirm:$false

       

       

       

      Thanks

       

       

      btw  I'm just beginning to do scripting with PowerCLI  !!!

        • 1. Re: Factory reset SNMP configuration with powerCLI
          VMDonttouch Lurker

          You can try ...

           

          PowerCLI C:\Scripts> $esx_hosts=get-vmhost <your-host-name>

           

          PowerCLI C:\Scripts> foreach ( $esx_h in $esx_hosts) {

          >> $esx=Get-EsxCli  -VMHost $esx_h.name -V2

          >> $snm_get=$esx.system.snmp.get.invoke()

          >> write-host "Before" $esx_h.name $snm_get.enable   $snm_get.communities

          >>

          >> }

          Before <your-host-name> false ihKtIhKQ4G5L5bdfHor2

           

          PowerCLI C:\Scripts> $snm_get

           

          authentication :

          communities    : {ihKtIhKQ4G5L5bdfHor2}

          enable         : false

          engineid       : 00000063000000a100000000

          hwsrc          : indications

          largestorage   : true

          loglevel       : info

          notraps        :

          port           : 161

          privacy        :

          remoteusers    :

          syscontact     :

          syslocation    :

          targets        :

          users          :

          v3targets      :

           

          PowerCLI C:\Scripts> foreach ( $esx_h in $esx_hosts) {

          >>                 $esx=Get-EsxCli  -VMHost $esx_h.name -V2

          >>                 $snm_get=$esx.system.snmp.get.invoke()

          >>                 write-host  "Before:" $esx_h.name $snm_get.enable   $snm_get.communities

          >>                 $snmpArgs=$esx.system.snmp.set.CreateArgs()

          >>                 $snmpArgs.communities="{}"

          >>                 $snmpArgs.enable="false"

          >>                 $esx.system.snmp.set.invoke($snmpArgs)

          >> }

          Before: <your-host-name> false ihKtIhKQ4G5L5bdfHor2

          true

          After:  <you-host-name> false

          PowerCLI C:\Scripts> $snm_get

           

           

          authentication :

          communities    : {}

          enable         : false

          engineid       : 00000063000000a100000000

          hwsrc          : indications

          largestorage   : true

          loglevel       : info

          notraps        :

          port           : 161

          privacy        :

          remoteusers    :

          syscontact     :

          syslocation    :

          targets        :

          users          :

          v3targets      :

          PowerCLI C:\Scripts>

           

          --------------------above actually didn't work I end up with '{}' string in community name  so I run below it seems to work  ----------

           

          PowerCLI C:\Scripts> foreach ( $esx_h in $esx_hosts) {

          >>                 $esx=Get-EsxCli  -VMHost $esx_h.name -V2

          >>                 $snm_get=$esx.system.snmp.get.invoke()

          >>                 write-host  "Before:" $esx_h.name $snm_get.enable   $snm_get.communities

          >>                 $snmpArgs=$esx.system.snmp.set.CreateArgs()

          >>                 $snmpArgs.reset="true"

          >>                 $snmpArgs.enable="false"

          >>                 $esx.system.snmp.set.invoke($snmpArgs)

          >>

          >> }

          PowerCLI C:\Scripts> $snm_get

           

          authentication :

          communities    :

          enable         : false

          engineid       :

          hwsrc          : indications

          largestorage   : true

          loglevel       : info

          notraps        :

          port           : 161

          privacy        :

          remoteusers    :

          syscontact     :

          syslocation    :

          targets        :

          users          :

          v3targets      :