IB_IT
Expert
Expert

need to modify a script for all hosts in vcenter

Jump to solution

Hi all,

I have the following script that works when connecting directly to an esxi host...need to modify this so I can attach to the vcenter so I can only run it once as opposed to on each host.

Basically I am trying to add a single IP address to one of the rulesets on all the hosts.

(Get-VMHost $esxhost )

$esxcli = Get-EsxCli -VMHost $esxhost

$esxcli.network.firewall.ruleset.allowedip.add("10.10.10.10", "vSphereClient")

This is probably simple, but when I try a FOREACH statement it just doesn't work.  Not very proficient with powercli

Any help would be appreciated!

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership

Try like this

Get-VMHost | %{

    $esxcli = Get-EsxCli -VMHost $_

    $esxcli.network.firewall.ruleset.allowedip.add("10.10.10.10", "vSphereClient")

}


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

View solution in original post

0 Kudos
3 Replies
LucD
Leadership
Leadership

Try like this

Get-VMHost | %{

    $esxcli = Get-EsxCli -VMHost $_

    $esxcli.network.firewall.ruleset.allowedip.add("10.10.10.10", "vSphereClient")

}


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

View solution in original post

0 Kudos
RvdNieuwendijk
Leadership
Leadership

To run the script on all of the hosts, you can use the following command:

(Get-VMHost | Get-EsxCli).network.firewall.ruleset.allowedip.add("10.10.10.10", "vSphereClient")

Blog: https://rvdnieuwendijk.com/ | Twitter: @rvdnieuwendijk | Author of: https://www.packtpub.com/virtualization-and-cloud/learning-powercli-second-edition
0 Kudos
IB_IT
Expert
Expert

Thanks for the replies!  LucD that worked like a charm, thanks a million.

0 Kudos