PowerShell: Remove Nic Teaming

# Check NIC Teaming
PS C:\Windows\system32> get-NetLbfoTeam
Name : ISCSI
Members : {iSCSI-B, iSCSI-A}
TeamNics : ISCSI
TeamingMode : SwitchIndependent
LoadBalancingAlgorithm : Dynamic
Status : Up

# Get NIC Team object and assign it to a variable
$teamName="ISCSI"
$teamInterface=Get-NetIPAddress -InterfaceAlias $teamName

# Remove IP Address
$teamInterface|Remove-NetIPAddress -Confirm:$false

# Remove Team members
$members=(get-NetLbfoTeam $teamName).Members
$members|%{Remove-NetLbfoTeamMember -Name $_ -Team $teamName -Confirm:$false}

<# error to be expected
Remove-NetLbfoTeamMember : Cannot remove the only member 'iSCSI-A' of team 'ISCSI'
At line:1 char:12
+ $members|%{Remove-NetLbfoTeamMember -Name $_ -Team $teamName -Confirm ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (MSFT_NetLbfoTea...E6B0A67E936C}"):root/StandardCi...tLbfoTeamMember) [
Remove-NetLbfoTeamMember], CimException
+ FullyQualifiedErrorId : MI RESULT 4,Remove-NetLbfoTeamMember
#>

# Remove NIC Team
Remove-NetLbfoTeam $teamName -Confirm:$false

# Set IP Address on NIC by its label
$interfaceAlias1="iSCSI-A"
$ipAddress1="1.1.1.1"
$netMask1="24"
$nicInterface1=Get-NetIPAddress -InterfaceAlias $interfaceAlias1
$nicInterface1|Set-NetIPAddress -IPAddress $ipAddress1 -PrefixLength $netMask1
Enable-NetAdapter -Name $interfaceAlias1

Leave a Reply

Your email address will not be published. Required fields are marked *