Thursday, March 15, 2012

Creating an External Virtual Switch in PowerShell and Windows 8

In a previous post I spent a lot of time trying to discover my physical NIC.

That was all leading up to this post.

Now, we need the Hyper-V cmdlets at the front:  Get-Command –Module Hyper-V and I want to create a new VM Switch so the cmdlet is New-VMSwitch.

New-VMSwitch needs a couple very basic pieces of information.  All of which we have seen in the GUI (Name, allow management OS, NetAdapterName, SwitchType, etc.

I need an Interface Name or Interface Description.  This is fine If I know what those are.  I can get that from Get-NetAdapter.

But, in my previous post I wanted to select the IP subnet that the NIC is attached to.

If I use this: Get-NetIPAddress –IPv4Address 10* | Get-NetIPInterface to return the NetIPInterface object to me based on a selection of the IPAddress starting with 192

I can used the returned NetIPInterface to then feed in to the Interface name or description of the New-VMSwitch cmdlet.

$if = Get-NetIPAddress –IPv4Address 192* | Get-NetIPInterface

The property ifAlias is the same as the NetAdapterName that New-VMSwitch is looking for.

New-VMSwitch –NetAdapterName $if.ifAlias -Name VMs

If you want to enable SR-IOV then you add the true at the end – you can only do this when you create a switch.

New-VMSwitch -NetAdapterName $if.ifAlias -Name VMs -EnableIov $true

Now, be aware of something.  The default behavior is to allow the Management OS to share this switch, so if you don’t want that to happen you have to be explicit about it.

New-VMSwitch -NetAdapterName $if.ifAlias -Name VMs –AllowManagementOS $false

No comments: