Hi all,
I am using push DSC to configure a 2 node Hyper-V cluster on Windows 2012 R2 Datacenter. This configuration creates a NIC Team called ‘HostTeam’ and a virtual switch called HostSwitch that is allowed to use the Management OS.
One of the problems I noticed was that one of my NIC’s, the NIC Team and the virtual switch all had the same MAC address and was generating a System error 16945 (MAC conflict: A port on the virtual switch has the same MAC as one of the underlying team members on Team Nic Microsoft Network Adapter Multiplexor Driver). The solution is to change the MAC Address on the NIC Team before creating the virtual switch. This ‘breaks’ the DSC configuration as manual input is required.
My boss wants me to automate the resolution, so I have been forced to add a Script resource to the DSC file. I have tested this and it does work, however I did find it difficult to find much information (in simple terms I can grasp) regarding the TestScript and GetScript
Script SetNicTeamMac {
SetScript = {
# Set MAC Address of NIC Team
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Get Adapter Names & MAC Addresses
$NIC = Get-NetAdapter
# Check for Duplicates and remove dashes
$Dup = ($NIC.MacAddress | Group | ?{$_.Count -gt 1}).Values
If ($Dup -gt 1){
$DupNIC = $NIC | Where {$_.MACAddress -eq $Dup} | Select Name, @{N='MacAddress'; E={$_.MacAddress -replace '-',""}}
# Get Highest MAC, convert to Decimal, increment by 1 and convert back to Hex
$Max = $NIC | Sort MACAddress | Select @{N='MacAddress'; E={$_.MacAddress -replace '-',""}} -Last 1
$Dec = [Convert]::ToInt64($Max.MacAddress, 16)
++$Dec
$Mac = [Convert]::ToString($Dec, 16)
# Assign to HostTeam - vLanId set to 0 as vSwitch will be tagged
Set-NetAdapterAdvancedProperty -InterfaceDescription "Microsoft Network Adapter Multiplexor Driver" -DisplayName "Mac Address" -DisplayValue $Mac
}
}
TestScript = {
$MacAddress = Get-NetAdapter HostTeam | Select MacAddress
return ($MacAddress.MacAddress -eq $Mac)
}
GetScript = {
$MacAddress = Get-NetAdapter HostTeam | Select MacAddress
Return @{
MacAddress = $MacAddress.MacAddress
}
}
DependsOn = '[cNetworkTeam]NetworkTeam'
}
I’d appreciate it if someone could give me some pointers (ways to improve) what I’ve done.
Thanks
Tony