This section provides additional content which was used in the “Windows Server 2012 Hyper-V Installation and Configuration Guide“:

Chapter 02 – Deploying Hyper-V

The XML file could look like the following:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<?xml version="1.0" encoding="utf-8"?>
<Config>
  <Host>
    <Computer Name="HYPERV21" Domain="server-talk.eu" WinSysLocal="en-US" />
    <VMHost VirtualMachinePath="C:\VMs" VirtualHardDiskPath="C:\VMs" MacAddressMinimum="00-15-5D-78-21-00" MacAddressMaximum="00-15-5D-78-21-FF" />
  </Host>
  <Network>
    <Teaming Name="Network Team" TeamMember1="00-17-A4-77-00-2B" TeamMember2="00-17-A4-77-00-2D"/>
    <VirtualSwitch Name="Public Network" BW="10" NetVirtDriver="true" />
  </Network>
  <NetworkAdapter>
    <PubMgmt Name="Public_Mgmt" IP="192.168.1.21" SubnetPrefix="24" Gateway="192.168.1.1" DNS1="192.168.1.101" DNS2="192.168.1.102" VLAN="" BW="5" />
    <PrivMigration Name="Private_Migration" IP="10.10.10.21" SubnetPrefix="24" VLAN="" BW="30" />
    <PrivCluster Name="Private_Cluster" IP="10.10.11.21" SubnetPrefix="24" VLAN="" BW="20" />
    <General DisableDisconnected="true" />
  </NetworkAdapter>
</Config

The PowerShell script would look like this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# ----------------------------------------------------------------------------------------------------
# Declare and define global variables
# ----------------------------------------------------------------------------------------------------
# Get XML Information
[XML]$ConfigXML = Get-Content ".\HostConfigFile.xml"
 
# Host OS Settings
$strComputerName = $ConfigXML.Config.Host.Computer.Name
$strComputerDomain = $ConfigXML.Config.Host.Computer.Domain
$strComputerWinSysLocal = $ConfigXML.Config.Host.Computer.WinSysLocal
 
# Hyper-V Settings (VM Host)
$strVirtualMachinePath = $ConfigXML.Config.Host.VMHost.VirtualMachinePath
$strVirtualHardDiskPath = $ConfigXML.Config.Host.VMHost.VirtualHardDiskPath
$strMacAddressMinimum = $ConfigXML.Config.Host.VMHost.MacAddressMinimum
$strMacAddressMaximum = $ConfigXML.Config.Host.VMHost.MacAddressMaximum
 
# Network Settings
$strNetworkTeamName = $ConfigXML.Config.Network.Teaming.Name
$strNetworkTeamMember1 = $ConfigXML.Config.Network.Teaming.TeamMember1
$strNetworkTeamMember2 = $ConfigXML.Config.Network.Teaming.TeamMember2
$strVirtualSwitchName = $ConfigXML.Config.Network.VirtualSwitch.Name
$strVirtualSwitchBW = $ConfigXML.Config.Network.VirtualSwitch.BW
$strNetVirtDriver = $ConfigXML.Config.Network.VirtualSwitch.NetVirtDriver
 
# Network Adapter Configuration
$strNICNamePubMgmt = $ConfigXML.Config.NetworkAdapter.PubMgmt.Name
$strNICPubMgmtIP = $ConfigXML.Config.NetworkAdapter.PubMgmt.IP
$strNICPubMgmtSubnet = $ConfigXML.Config.NetworkAdapter.PubMgmt.SubnetPrefix
$strNICPubMgmtGW = $ConfigXML.Config.NetworkAdapter.PubMgmt.Gateway
$strNICPubMgmtDNS1 = $ConfigXML.Config.NetworkAdapter.PubMgmt.DNS1
$strNICPubMgmtDNS2 = $ConfigXML.Config.NetworkAdapter.PubMgmt.DNS2
$strNICPubMgmtVLAN = $ConfigXML.Config.NetworkAdapter.PubMgmt.VLAN
$strNICPubMgmtBW = $ConfigXML.Config.NetworkAdapter.PubMgmt.BW
$strNICNamePrivMigration = $ConfigXML.Config.NetworkAdapter.PrivMigration.Name
$strNICPrivMigrationIP = $ConfigXML.Config.NetworkAdapter.PrivMigration.IP
$strNICPrivMigrationSubnet = $ConfigXML.Config.NetworkAdapter.PrivMigration.SubnetPrefix
$strNICPrivMigrationVLAN = $ConfigXML.Config.NetworkAdapter.PrivMigration.VLAN
$strNICPrivMigrationBW = $ConfigXML.Config.NetworkAdapter.PrivMigration.BW
$strNICNamePrivCluster = $ConfigXML.Config.NetworkAdapter.PrivCluster.Name
$strNICPrivClusterIP = $ConfigXML.Config.NetworkAdapter.PrivCluster.IP
$strNICPrivClusterSubnet = $ConfigXML.Config.NetworkAdapter.PrivCluster.SubnetPrefix
$strNICPrivClusterVLAN = $ConfigXML.Config.NetworkAdapter.PrivCluster.VLAN
$strNICPrivClusterBW = $ConfigXML.Config.NetworkAdapter.PrivCluster.BW
$strNICDisconnected = $ConfigXML.Config.NetworkAdapter.General.DisableDisconnected
 
# Configure Operating System
# ----------------------------------------------------------------------------------------------------
Write-Output ‘Renaming computer’
Rename-Computer -NewName $strComputerName
Write-Output ‘Joining domain’
Add-Computer -DomainName $strComputerDomain
Write-Output ‘Changing Windows system local language’
Import-Module International
Set-WinSystemLocale -SystemLocale $strComputerWinSysLocal
 
# Install Hyper-V
# ----------------------------------------------------------------------------------------------------
Write-Output ‘Installing Multipath-IO Feature’
Add-WindowsFeature Multipath-IO
Write-Output ‘Installing Failover Cluster Feature’
Add-WindowsFeature Failover-Clustering -IncludeManagementTools
Write-Output ‘Installing Hyper-V Role’
Add-WindowsFeature Hyper-V -IncludeManagementTools -Restart
 
# Configure Classic Network
# ----------------------------------------------------------------------------------------------------
Write-Output ‘Creating network team’
Get-NetAdapter -Physical | Where-Object {$_.MacAddress -eq $strNetworkTeamMember1} | Rename-NetAdapter -NewName "Converged Team (Adapter 1)"
Get-NetAdapter -Physical | Where-Object {$_.MacAddress -eq $strNetworkTeamMember2} | Rename-NetAdapter -NewName "Converged Team (Adapter 2)"
 
$strNetworkTeamMembers = Get-NetAdapter -Physical | Where-Object {$_.Name -like "Converged Team (Adapter *" }
New-NetLbfoTeam -Name $strNetworkTeamName -TeamMembers $strNetworkTeamMembers.Name -TeamingMode SwitchIndependent -LoadBalancingAlgorithm TransportPorts
 
If ($strNICDisconnected -eq "true") {
  Write-Output ‘Disabling disconnected network adapters’
  Get-NetAdapter -Physical | Where-Object {$_.Status -eq "Disconnected" } | Disable-NetAdapter }
 
Write-Output ‘Creating a new virtual Switch with one default virtual port for parent partition’
New-VMSwitch -Name $strVirtualSwitchName -MinimumBandwidthMode weight -NetAdapterName $strNetworkTeamName
 
Write-Output ‘Renaming the virtual port for the parent partition’
Rename-VMNetworkAdapter -ManagementOS -Name $strVirtualSwitchName -NewName $strNICNamePubMgmt
 
Write-Output ‘Creating addional virtual ports for the parent partition’
Add-VMNetworkAdapter -ManagementOS -Name $strNICNamePrivMigration -SwitchName $strVirtualSwitchName
Add-VMNetworkAdapter -ManagementOS -Name $strNICNamePrivCluster -SwitchName $strVirtualSwitchName
 
Write-Output ‘Assigning the default Virtual Port to a VLAN’
Set-VMNetworkAdapterVlan -ManagementOS -VMNetworkAdapterName $strNICNamePubMgmt -Access -VlanId $strNICPubMgmtVLAN
Set-VMNetworkAdapterVlan -ManagementOS -VMNetworkAdapterName $strNICNamePrivMigration -Access -VlanId $strNICPrivMigrationVLAN
Set-VMNetworkAdapterVlan -ManagementOS -VMNetworkAdapterName $strNICNamePrivCluster -Access -VlanId $strNICPrivClusterVLAN
 
Write-Output ‘Assigning IPv4 addresses to virtual ports in parent partition’
New-NetIPAddress -IPAddress $strNICPubMgmtIP -InterfaceAlias "vEthernet ($strNICNamePubMgmt)" -PrefixLength $strNICPubMgmtSubnet -DefaultGateway $strNICPubMgmtGW
New-NetIPAddress -IPAddress $strNICPrivMigrationIP -InterfaceAlias "vEthernet ($strNICNamePrivMigration)" -PrefixLength $strNICPrivMigrationSubnet
New-NetIPAddress -IPAddress $strNICPrivClusterIP -InterfaceAlias "vEthernet ($strNICNamePrivCluster)" -PrefixLength $strNICPrivClusterSubnet
 
Write-Output ‘Assigning DNS Server for virtual ports in parent partition’
Set-DnsClientServerAddress -InterfaceAlias "vEthernet ($strNICNamePubMgmt)" -ServerAddresses $strNICPubMgmtDNS1, $strNICPubMgmtDNS2
 
Write-Output ‘Disable DNS registration for private network adapters’
$strVNICNamingPrivMigration = "vEthernet (" + $strNICNamePrivMigration + ")"
Set-DnsClient -InterfaceAlias $strVNICNamingPrivMigration -RegisterThisConnectionsAddress $false 
$strVNICNamingPrivCluster = "vEthernet (" + $strNICNamePrivCluster + ")"
Set-DnsClient -InterfaceAlias $strVNICNamingPrivCluster -RegisterThisConnectionsAddress $false
 
Write-Output ‘Assigning Minimum Bandwidth to ports’
Set-VMNetworkAdapter -ManagementOS -Name $strNICNamePubMgmt -MinimumBandwidthWeight $strNICPubMgmtBW
Set-VMNetworkAdapter -ManagementOS -Name $strNICNamePrivMigration -MinimumBandwidthWeight $strNICPrivMigrationBW

The End