Windows Server 2012 – Create network settings for Hyper-V cluster with Powershell

Windows 2012 has some great new network features that makes network usage much more efficient. Till Windows 2012 it was necessary to use dedicated NICs for certain network traffic (Cluster, Storage). But with Windows 2012 we can virtualize the network by creating NIC Teams and Extensible Switches and Virtual Adapters.

So when you are building a Hyper-V cluster, it’s not necessary anymore to load a lot of NICs in a server. Instead we create a NIC Team that bundles all the available Network NICs (whatever hardware mix, doesn’t matter), create a Virtual Switch and then Virtual Adapters. To make it more easy Aiden Finn created a PowerShell script that does all the work. I adjusted it a bit and the result is an automated network configuration for Hyper-V in Windows 2012.

To make this PowerShell script working, you need to know your network. So prepare IP addresses for: Management, Cluster, Live Migration and iSCSI (I commented out the secondary iSCSI for multipathing). Change the addresses in the script, save and run it. This script is without VLAN configuration, but it works great for my computer lab.

UPDATE:

I added the VLAN configuration to the bottom of the script. In my case I created a iSCSI VLAN.

PowerShell script:

write-host “Creating NIC Team with NICs” New-NetLbfoTeam -Name “NicTeam” -TeamMembers *

write-host “Creating virtual switch with QoS enabled” New-VMSwitch “ExtensibleSwitch” -MinimumBandwidthMode weight -NetAdapterName “NicTeam” -AllowManagementOS 0

write-host “Setting default QoS policy” Set-VMSwitch “ExtensibleSwitch” -DefaultFlowMinimumBandwidthWeight 10

write-host “Creating virtual NICs for the management OS” Add-VMNetworkAdapter -ManagementOS -Name “Management” -SwitchName “ExtensibleSwitch” Set-VMNetworkAdapter -ManagementOS -Name “Management” -MinimumBandwidthWeight 10

Add-VMNetworkAdapter -ManagementOS -Name “Cluster” -SwitchName “ExtensibleSwitch” Set-VMNetworkAdapter -ManagementOS -Name “Cluster” -MinimumBandwidthWeight 10

Add-VMNetworkAdapter -ManagementOS -Name “LiveMigration” -SwitchName “ExtensibleSwitch” Set-VMNetworkAdapter -ManagementOS -Name “LiveMigration” -MinimumBandwidthWeight 10

Add-VMNetworkAdapter -ManagementOS -Name “iSCSI” -SwitchName “ExtensibleSwitch” Set-VMNetworkAdapter -ManagementOS -Name “iSCSI” -MinimumBandwidthWeight 10

#Add-VMNetworkAdapter -ManagementOS -Name “iSCSI2” -SwitchName “ExtensibleSwitch” #Set-VMNetworkAdapter -ManagementOS -Name “iSCSI2” -MinimumBandwidthWeight 15

write-host “Waiting 30 seconds for virtual devices to initialise” Start-Sleep -s 30

write-host “Configuring IPv4 addresses for the Virtual NICs” New-NetIPAddress -InterfaceAlias “vEthernet (Management)” -IPAddress 192.168.1.10 -PrefixLength 16 -DefaultGateway 192.168.1.1 Set-DnsClientServerAddress -InterfaceAlias “vEthernet (Host-Parent)” -ServerAddresses “192.168.1.40”

New-NetIPAddress -InterfaceAlias “vEthernet (Cluster)” -IPAddress 10.20.100.10 -PrefixLength 16 New-NetIPAddress -InterfaceAlias “vEthernet (LiveMigration)” -IPAddress 10.30.100.10 -PrefixLength 16 New-NetIPAddress -InterfaceAlias “vEthernet (iSCSI)” -IPAddress 10.10.100.10 -PrefixLength 16 #New-NetIPAddress -InterfaceAlias “vEthernet (iSCSI2)” -IPAddress 10.10.100.11 -PrefixLength 16

Set-VMNetworkAdapterVlan -ManagementOS -Access -VlanId 4 -VMNetworkAdapterName iSCSI

Leave a Reply

  

  

  

*

This site uses Akismet to reduce spam. Learn how your comment data is processed.