Trying to script for an Auto build the Teaming of NICs in 2012 R2 Server, I'm running into a problem trying to assign the IP address to the new Teamed NIC using WMI. What am I missing?
I had just added the split for the DNS string, I haven't tested that yet, the problem is with the WMI methods to write the IP to the new NIC, I'm getting result values of 70 for the IP, (Invalid IP address).
I had just added the split for the DNS string, I haven't tested that yet, the problem is with the WMI methods to write the IP to the new NIC, I'm getting result values of 70 for the IP, (Invalid IP address).
[String]$TeamingDesc = "Microsoft Network Adapter Multiplexor Driver"
[Array]$GWMetric = 1
#[String]$IP = ""
#[String]$SubN = ""
#[String]$GW = ""
#[String]$DNS = ""
#[String]$WinsPrimary = ""
#[String]$WinsSecondary = ""
$ipaddress = Get-WmiObject win32_networkadapterconfiguration -filter "DHCPEnabled = 'False'"
[Array]$IP = $ipaddress.Ipaddress
[Array]$SubN = $ipaddress.IPSubnet
[Array]$GW = $ipaddress.DefaultIPGateway
[String]$DNS = $ipaddress.DNSServerSearchOrder
[Array]$WinsPrimary = $ipaddress.WINSPrimaryServer
[Array]$WinsSecondary = $ipaddress.WINSSecondaryServer
[Array]$DNSSplit = $DNS.split(" ")
Write-Host $IP
Write-Host $SubN
Write-Host $GW
Write-Host $DNS
Write-Host $DNSSplit[0]
Write-Host $DNSSplit[1]
$Interfacename = @()
$ConnectedNics = Get-NetIPInterface -ConnectionState Connected | where {$_.InterfaceAlias -Match "Ethernet*"}
foreach($line in $ConnectedNics){
$Interfacename += $line.InterfaceAlias
}
New-NetLbfoTeam -Name ProdTeam -TeamMembers $Interfacename[0],$Interfacename[1] -TeamingMode SwitchIndependent -Confirm:$false
Set-NetLbfoTeamMember -Name "$Interfacename[1]" -AdministrativeMode Standby
$TeamedNic = Get-WmiObject Win32_NetworkAdapterConfiguration -Filter "Description = 'Microsoft Network Adapter Multiplexor Driver'"
$TeamedNic.EnableStatic("$IP", "$SubN")
$TeamedNic.SetGateways($GW, 1)
$teamedNic.SetDNSServerSearchOrder($DNS)
$teamedNic.SetWINSServer($WinsPrimary,$WinsSecondary)The Write-Host stmts are in there for debugging..
Thank you,
Bryan