Unique portgroup fiddling with #Powercli.
As my peers seem to like to flout convention, particularly naming conventions. I was left with a strange automation challenge this week.
with a new service coming online in my company, I had 12 vlan portgroups to add to over 30 ESXi machines. Simple you say, just pipe your hosts into a new virtualswitch query then into a new virtual port group command.
Did i mention the virtual switch has a different name per host? Its vswitch0 on some, vswitch1 on others, and even vswitch2 on one.Arse.
after a few hours of various queries, below is the little scripty I was left with. I did consider putting this into a function, but I didnt know where to begin when it came to a name…
add-PortGroupInSwitchWhereOtherPortGroupExists? … bleh.
Below the variables are pretty self explanatory and it works flawlessly. Remember to install the powercli commands, import the module and connect to the vi server first!
#Variables $findportgroupname="GWA4" $NewPortGroupName="Citrix7" $NewPortGroupVlanId="306" foreach ($portgroup in get-virtualportgroup | where {$_.name -eq $findportgroupname}){ get-vmhost -id $portgroup.vmhostid | get-virtualswitch -name $portgroup.virtualswitchname | new-virtualportgroup -name $NewPortGroupName -Vlanid $NewPortGroupVlanId }
Recent Comments