Here is where I take my two previous posts and splice them together into something useful.
The previous posts contain the details of picking through the various portions of the script, here I just toss it together with some useful loops and work through the Groups that I created.
Once again, this is all PowerShell v3 and Server 2012.
Recall that my scenario is:
Someone racked this server, they jacked it to the management network, the VM production network, and the storage network. I want to know what NICs are jacked where and group and summarize them. And each of these networks has DHCP running as I have no time to manually assign IP addresses any longer. They are divided physically in the top of the rack with three switches.
The meat of the script is:
$ips = Get-NetAdapter -Physical | where {$_.Status -eq "Up"} | Get-NetIPConfiguration | Group-Object -property IPv4DefaultGateway
foreach ($group in $ips) {
# test for no gateway we expect DHCP to give one, if there isn’t one then this really isn’t useful is it?
If ([string]$group.Values.nexthop -ne "0.0.0.0") {$nicList = @()
foreach ($nic in $group.Group) {
$nicList += $nic.InterfaceAlias
}$name = [string]$group.Values.nexthop
$team = New-NetLbfoTeam -Name $name -TeamNicName ($name + "Team") -TeamMembers ($nicList) -TeamingMode SwitchIndependent -LoadBalancingAlgorithm HyperVPort -Confirm:$false
Clear-Variable -Name nicListDo {$team = Get-NetLbfoTeam -Name $team.Name
sleep 2}
until ($team.Status -eq "Up")Get-NetIPAddress -InterfaceAlias $team.TeamNics | select IPAddress
}
}
The default LoadBalancingAlgorithm is TransportPorts and works in most general cases.
If the team is specific to supporting VMs and it has an External Virtual Switch attached then HyperVPort should be used.