Powershell Network Load Balancing

Teched 2010 Berlin #TEE10 #Teched

For Demo and learning Sites you need often thing that takes only a minute but when you play with it it takes more time than you want. So with this in my mind I created 3 powershell scripts that you can use for building a cluster , NLB Cluster and a MSTDC cluster resource.

This powershell script is fully unattended an yes it is not complete it can be improved.  But you can always adjust this. Similar scripts are there for creating Exchange NLB.

This script runs on node 1 and is creating the NLB on the two or more nodes. ( tested only on two nodes )

You can find the Scripts Here : Powershell Scripts

Powershell Create NLB

The first thing you might want to change is the network adapter name I used adapter 3 and renamed it to NLB later in the NLB name is used as parameter,

#Set IP for NLB Write-Host "Set NLB IP and change Network adapter" -ForegroundColor yellow Netsh interface ip set address name="Local Area Connection 3" static 1.1.1.1 255.255.255.0 Netsh interface set interface name="local area connection 3" newname="NLB"

The Ip adress is needed to set the NLB don’t worry the IP will be removed when the NLB is complete.

The other part is the powershell script is connecting thrue powershell to the other node.

First give the netbios name from the second node ( make sure your DNS is OK )

#Adding additional cluster nodes based on user input
Write-Host "Give Second NLB host" -ForegroundColor yellow
$Node2Fqdn = Read-Host "Enter 2e NLB node"

Here with the “function EndPSS { get-pssession | remove-pssession } “
and “endpss “ I connect and disconnect to the other node. the problem here was. in the basic security you can only use 5 remote connections. I can adjust this or make a workaround so the script works in the default security template.

Now I connect from node 1 to node 2 and placed a IP and renamed the NIC

function EndPSS { get-pssession | remove-pssession }
#Set Network Adapter
#Enter-PSSession -ComputerName $Node2Fqdn
invoke-command -computername $Node2Fqdn -scriptblock { Netsh interface ip set address name="local area connection 3" static 1.1.1.2 255.255.255.0}
invoke-command -computername $Node2Fqdn -scriptblock { Netsh interface set interface name="local area connection 3" newname="NLB"}
Write-Host "Placed NLB IP and changed NIC to NLB" -ForegroundColor yellow
exit-PSSession
endpss

#Import-Module NetworkLoadBalancingClusters
Write-Host "Import-Module NetworkLoadBalancingClusters On Remote Node" -ForegroundColor yellow
Enter-PSSession -ComputerName $Node2Fqdn
invoke-command -computername $Node2Fqdn { Import-Module NetworkLoadBalancingClusters}
exit-pssession
endpss

#Add Remote Node To NLB
Write-Host "Adding cluster node $Node2Fqdn" -ForegroundColor yellow
Get-NlbCluster | Add-NlbClusterNode -NewNodeName $Node2Fqdn -NewNodeInterface NLB

#Remove Old IP
Remove-NlbClusterNodeDip 1.1.1.2 -Hostname $Node2Fqdn -force
Write-Host " Remove old IP node " -ForegroundColor yellow

Here I removed the IP that was needed to create the NLB.

You can find the Scripts Here : Powershell Scripts

Powershell Create NLB

  • Tag