Creating portgroups with PowerShell
I must be a workaholic. I was browsing my laptop for some movie and I came across a folder with all kinds of plugins for VirtualCenter. Things like addPortgroup and other stuff.
Although it’s very handy to use those plugins I like to be able to these kind of things from the commandline, so I started some PowerShell script (here is where the workaholic starts) to create portgroups on all your VMware hosts that are known by VirtualCenter.
I wanted to make it a oneliner, but that was too much. My PowerShell scripting powers aren’t that good that I can get it to work :)
So here it is with a couple of lines. It creates a portgroup on vSwitch0 with PG as name and VLAN 99. Ofcourse it only works if you use the VI Toolkit from VMware.
foreach ($vmhost in get-vmhost)
new-VirtualPortGroup -name PG -VirtualSwitch (Get-virtualswitch -VMHost $vmHost -name vSwitch0) -VLAN 99
Happy holidays again :)
- PowerShell Friday: Configuring vSphere MTU Size by Martijn Smit
- PowerShell Friday: Enabling SSH with PowerCLI by Anne Jan Elsinga
- PowerShell Friday: Creating Virtual Machines by Sander Martijn
- Veeam PowerShell: Get Backup Job Storage Size by Martijn Smit
- Installing vRealize Network Insight with PowerCLI by Martijn Smit