Archives


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 :)

Google BookmarksEmailHyvesStumbleUponLinkedInShare

Related posts:

  1. More PowerShell stuff
  2. VMware and PowerShell
  3. Searching for a VM
  4. Managing VMware with PowerShell FAQ
  5. Vizioncore vProduct range

Tags:

About

Anne Jan Elsinga is a Consultant for Imtech ICT in the Netherlands. He spends his working hours with a lot of virtualization stuff, from feasibility to implementation for server virtualization/consolidation and desktop virtualization. In 2009, 2010 and 2011 he was awarded with the VMware vExpert status. In the night time he dances latin, ballroom and salsa and he also discovered the pleasure of diving.

Comments are closed.