In Part 1 and Part 2 of this series I detailed the steps required to deploy BMC (Bare Metal Deploy) and configure the physical network adapter settings using Logical Networks and Logical Switches created in VMM. In this post, I will provide an overview of the necessary steps to configure the physical network adapter settings, create virtual switches and virtual network adapters using Logical Switches, and VM Networks created in VMM through PowerShell.

If you are not familiar with the concepts of networking in VMM, you can read more on TechNet.

The Solution through the PowerShell Approach:

The PowerShell approach is very handy and reusable – especially when many servers need to be provisioned in the offline mode in an automated way. This post features tips on using the networking Cmdlets in VMM, leveraging the new networking features such as Logical Switch, Uplink port profile and Virtual port profile.

Before using the PowerShell, make sure you setup the Hyper-V host (through BMC deployment or other mechanism you follow to install OS) and the host is added to VMM for managing.

Here are the network pre-requisites to setup in VMM before the network setting is applied on to the Hyper-V host:

  • Create one or more Logical Networks to map to the NICs on bare-metal servers.
  • Create one or more Logical Switches that encompass the following networking capabilities and properties to be assigned to the NICs on hyper-v host servers.
    • Extensions (not discussed in this post).
    • Uplink (Contains Uplink Mode for NIC Teaming and one or more Uplink Port Profiles for specifying the NIC teaming mode, load balancing algorithm and the network sites it applies to).
    • Virtual Port (Contains one or more virtual port classifications for assigning it to various virtual network adapter workloads based on the bandwidth requirement).

Here are the basic steps to follow in setting the physical and virtual network adapter settings onto Hyper-V host:

1. Import “Virtual Machine Manager” Powershell module if not loaded

If (!(Get-Module VirtualMachineManager)) {Import-Module VirtualMachineManager}

2. Initialize the variable required for the Cmdlet: (Note: Replace values to match your environment)

$ComputerName = "DCMRR25OSD19N28" #Hyper-V Host Computer

$LSwitch1 = "LSForBMC"                              #Logical Switch Name

$NativeUPP1 = "UPPForBMC"                      #Uplink Port Profile Name

3. Get VMM Objects for the following items:

  • Logical Switch for setting Virtual Switch with NIC teamed physical adapters
  • Native Uplink Port Profile and Profile Set for setting NIC team in physical NIC
  • Port Classification for QoS setting in Virtual NIC

$LogicalSwitch1 = Get-SCLogicalSwitch -Name $LSwitch1

$NativeUplinkPortProfile1 = Get-SCNativeUplinkPortProfile -name $NativeUPP1

$UplinkPortProfileSet1 = Get-SCUplinkPortProfileSet | where { $_.NativeUplinkPortProfile.Name -eq $NativeUPP1 }

4. Get VMM Objects for the following items:

  • Port Classification to be used for Host Management virtual network adapter
  • Port Classification to be used for Cluster virtual network adapter
  • Port Classification to be used for Live Migration virtual network adapter

$PortClassificationHost = Get-SCPortClassification -Name "Host management"

$PortClassificationCluster = Get-SCPortClassification -Name "Host Cluster Workload"

$PortClassificationLive = Get-SCPortClassification -Name "Live migration workload"

5. Get VMM Objects for the following items:

  • VM Network to be used for Host Management virtual network adapter
  • VM Network to be used for Cluster virtual network adapter
  • VM Network to be used for Live Migration virtual network adapter

$VMNetworkHost = Get-SCVMNetwork -Name "VMNForHost"

$VMNetworkCluster = Get-SCVMNetwork -Name "VMNForCluster"

$VMNetworkLive = Get-SCVMNetwork -Name "VMNForLive"

6. Get Subnet and Static IP Pool for the virtual NIC setting

$VMSubnet = Get-SCVMSubnet -VMNetwork $VMNetworkHost -Name "HostvNICSubnet"

$ipV4Pool = Get-SCStaticIPAddressPool -Name "HostvNICIPPool"

7. Get the Hyper-V host computer object in VMM

$VMHost = Get-SCVMHost -ComputerName $ComputerName

8. Create new GUID for submitting the VMM Cmdlets in group as job:

$Jguid=[System.Guid]::Newguid().ToString()

9. Initialize Array variable to hold physical network adapter settings:

$HostNetworkAdapter=@()

10. Get all physical network adapter objects on the Hyper-V host

$VMHostNetworkAdapter=get-scvmhostnetworkadapter -VMHost $VMHost

11. Read through and select the physical network adapters and set the Uplink port profile setting for teaming those adapters.

$VMHostNetworkAdapter | ForEach-Object {

if($_.ConnectionName -eq "Ethernet 3")

{

$HostNetworkAdapter += $_

Set-SCVMHostNetworkAdapter -VMHostNetworkAdapter $_ -UplinkPortProfileSet $UplinkPortProfileSet1 -JobGroup $Jguid

}

if($_.ConnectionName -eq "Ethernet 4")

{

$HostNetworkAdapter += $_

Set-SCVMHostNetworkAdapter -VMHostNetworkAdapter $_ -UplinkPortProfileSet $UplinkPortProfileSet1 -JobGroup $Jguid

}

}

                 
Sample Output for $HostNetworkAdapter:

$HostNetworkAdapter | fl name, connectionname, uplinkportprofileset

Name                 : HP NC362i Integrated DP Gigabit Server Adapter #3
ConnectionName       : Ethernet 3
UplinkPortProfileSet : UPPForBMC_c0f09141-f140-4931-a7d3-90ec6607a3b8

Name                 : HP NC362i Integrated DP Gigabit Server Adapter #4
ConnectionName       : Ethernet 4
UplinkPortProfileSet : UPPForBMC_c0f09141-f140-4931-a7d3-90ec6607a3b8

12. Check virtual switch setting on the Hyper-V host and set/add the teamed adapters to it

$HostVirtualNetwork=Get-SCVirtualNetwork -Name $LSwitch1

if($HostVirtualNetwork -eq $null)

{

New-SCVirtualNetwork -VMHost $VMHost -LogicalSwitch $LogicalSwitch1 -VMHostNetworkAdapters $HostNetworkAdapter -JobGroup $Jguid

}

else

{

$HostNetworkAdapter+=$HostVirtualNetwork.VMHostNetworkAdapters

Set-SCVirtualNetwork -VirtualNetwork $HostVirtualNetwork -LogicalSwitch $LogicalSwitch1 -VMHostNetworkAdapters $HostNetworkAdapter -JobGroup $Jguid

}

13. Create the required virtual NICs using VM Network and IP Pool settings

New-SCVirtualNetworkAdapter -VMHost $VMHost -Name "LSForBMC6" -VMNetwork $VMNetworkCluster -LogicalSwitch $LogicalSwitch1 -VMSubnet $VMSubnet -IPv4AddressType "Static" -IPv4AddressPool $ipV4Pool -PortClassification $PortClassificationCluster -JobGroup $Jguid

New-SCVirtualNetworkAdapter -VMHost $VMHost -Name "LSForBMC7" -VMNetwork $VMNetworkLive -LogicalSwitch $LogicalSwitch1 -VMSubnet $VMSubnet -IPv4AddressType "Static" -IPv4AddressPool $ipV4Pool -PortClassification $PortClassificationLive -JobGroup $Jguid

14. Apply the new network settings on the Hyper-V host through the VMM job

Set-SCVMHost -VMHost $VMHost -JobGroup $Jguid -RunAsynchronously

15. Check the VMM Job output for the completion of Job and also check the target Hyper-V host for the correct

network settings

- Select properties for the Hyper-V host and check under “Virtual Switches” for the correct network settings for virtual switch and virtual network adapters

- Also, you can verify using the VMM PowerShell Cmdlet:

  • Check virtual switch on Hyper-V host:

PS C:\> get-scvirtualnetwork -VMHost $VMHost | fl name, logicalnetworks, logicalswitch, vmhostnetworkadapters

Name                  : LSForBMC
LogicalNetworks       : {LNForBMC}
LogicalSwitch         : LSForBMC
VMHostNetworkAdapters : {HP NC362i Integrated DP Gigabit Server Adapter #3, HP NC362i Integrated DP Gigabit Server Adapter #4}

  • Check virtual network adapters on Hyper-V host:

PS C:\> get-scvirtualnetworkadapter -vmhost $VMHost | fl name, logicalswitch,virtualnetwork, vmnetwork,portclassification

Name               : LSForBMC6
LogicalSwitch      : LSForBMC
VirtualNetwork     : LSForBMC
VMNetwork          : VMNForBMC
PortClassification : Host Cluster Workload

Name               : LSForBMC7
LogicalSwitch      : LSForBMC
VirtualNetwork     : LSForBMC
VMNetwork          : VMNForBMC
PortClassification : Live migration  workload

Summary

Use the above Cmdlets as reference and make sure the hard coded values are replaced to match the environment.

In my next post I will focus on automating the storage management through Virtual Machine Manager.