2 Replies Latest reply on Dec 15, 2010 5:58 AM by LucD

    Arrays in powershell & restarting services

    peter79 Enthusiast

      Guys,

       

      I'm currently trying to write a script to confiugre SNMP settings on multiple ESX hosts.  I'm able to wtire the code that configures the SNMP but I need help with 2 things.

       

      Firstly I'm trying to create an array to hold all the ESX host names.  I know that I could use "$hosts=get-vmhost | name" but a few of the hosts all ready have SNMP configured correctly.  Can you create an array and manually give it a list of host names?

       

      Secondly I will need to restart the snmp service after its configured.  I know how to do this in the ESX conolse but am not sure how to script it in powershell.

       

      Thanks in advance guys.       

        • 1. Re: Arrays in powershell & restarting services
          LucD Guru
          User ModeratorsvExpertCommunity Warriors

          There are several ways to populate an array.

           

          $array = @"

          host1

          host2

          host3

          "@

           

          or

           

          $array = "host1",host2","host3"

           

          I'm afraid you can stop/start the SNMP service from PowerCLI.

          • 2. Re: Arrays in powershell & restarting services
            LucD Guru
            Community WarriorsvExpertUser Moderators

            Btw, you can't restart the SNMP service on ESXi host but you can enable/disable it with PowerCLI.

            Connect to the ESXi server (not the vCenter) and do

             

            Get-VMHostSnmp | Set-VMHostSnmp -Enabled:$true -AddTarget -TargetHost "myHost" -TargetCommunity "public"

             

            and

             

            Get-VMHostSnmp | Set-VMHostSnmp -Enabled:$false

             

            In fact why do you need to stop/start the SNMP service ?

            You can change target hosts, communities ... on the fly.

             

            Update: just did a bit of recerse-engineering on the vicfg-snmp.pl file.

            And in fact what is called Stop and Start in that script is the -Enable:$true and -Enable:$false on the Set-VMHostSnmp cmdlet.

            So, you can do exactly the same thing with PowerCLI.