VMware Cloud Community
peter79
Enthusiast
Enthusiast

Arrays in powershell & restarting services

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.       

Reply
0 Kudos
2 Replies
LucD
Leadership
Leadership

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.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
LucD
Leadership
Leadership

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.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos