Home > Blogs > VMware PowerCLI Blog


vDS in PowerCLI 4.1

At last vDS features are here with the new PowerCLI . The vSphere PowerCLI 4.1 release is the first touch of PowerCLI with vNetwork distributed switches, so please don’t expect to find fully supported vDS functionality in it. Still as you probably know, the Get-View cmdlet provides an opportunity to add extra functionality to your PowerCLI scripts. What you’re going to find in this post is how to create virtual network adapters on vDS and how to move VMs in and out of a vDS. At the bottom you can find a sample function that creates vDS.

When you have your vDS ready, you can create your virtual network adapters there. What you have to know is the name of the vDS and the name of the port group that you’re going to use. The line below will create VMKernel adapter with DHCP settings on the specified vDS and port group:

New-VMHostNetworkAdapter -VMHost $myHost -VirtualSwitch “myVDS”-PortGroup “dvPortGroup”

 

You can move VMs in and out of a vDS. Again, the only thing you have to know is the name of the port group:

$vm | Get-NetworkAdapter | Set-NetworkAdapter -NetworkName “vdPortGroup”

On the same principle you can create new network adapters directly on your vDS:

New-NetworkAdapter -VM $vm -NetworkName “vdPortGroup”

And you can directly create VM, specifying its network adapter, to be on vDS network:

New-VM -Name “myVM” -VMHost $myHost -DiskMB 10240 -NetworkName “vdPortGroup”

The sample function below creates vDS, using the vSphere SDK for .Net. First, the function creates DVSCreateSpec, where vDS name and uplink port names are populated (Note that the name of the class matches the previous name of the vDS – “distributed virtual switches”, instead of “vNetwork distributed switches”. So don’t be confused of that ). Then the function creates DistributedVirtualSwitchHostMemberConfigSpec, where it populates the host(s), which will be added to the vDS. For the example I am adding a single ESX host, but you can modify the function to add a collection of hosts. For the added hosts, the function specifies the physical network adapter ID, which will be used for the connection to the vDS, which is done by adding DistributedVirtualSwitchHostMemberPnicSpec. Next, the function creates the vDS using CreateDVS method of the network folder view. Then the function creates DVPortgroupConfigSpec and adds a port group using the AddDVPortgroup method of the vDS view. Finally the function returns the managed object reference of the vDS.

 

 

 

Having the vDS managed object reference, later we can delete the vDS:

$vdsView = Get-View -Id $vdsMoRef

$vdsView.Destroy()

One thing you have to remember is that you won’t be able to remove your vDS until there are virtual adapters available there.

I hope that you’ll find this post somehow helpful and that it will make you feel a little bit more comfortable, when working with vNetwork distributed switches .

3 thoughts on “vDS in PowerCLI 4.1

  1. Robert van den Nieuwendijk

    I think that there is a type in the function and that line 52 should read:
    $vdsMoRef = $networkFolderView.CreateDVS($vdsCreateSpec)

    Reply
  2. Pavel Dimitrov

    Thanks Robert! I fixed it. The reason for the typo was the difference between the official feature name (vDS) and the legacy method name which differs in the abbreviation (CreateDVS). As I recall I renamed all my variables to match the official feature name and missed this one.

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

*