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

Author: Robert Smit [MVP]

Robert Smit is Senior Technical Evangelist and is a current Microsoft MVP in Clustering as of 2009. Robert has over 20 years experience in IT with experience in the educational, health-care and finance industries. Robert’s past IT experience in the trenches of IT gives him the knowledge and insight that allows him to communicate effectively with IT professionals who are trying to address real concerns around business continuity, disaster recovery and regulatory compliance issues. Robert holds the following certifications: MCT - Microsoft Certified Trainer, MCTS - Windows Server Virtualization, MCSE, MCSA and MCPS. He is an active participant in the Microsoft newsgroup community and is currently focused on Hyper-V, Failover Clustering, SQL Server, Azure and all things related to Cloud Computing and Infrastructure Optimalization. Follow Robert on Twitter @ClusterMVP Or follow his blog https://robertsmit.wordpress.com Linkedin Profile Http://nl.linkedin.com/in/robertsmit Robert is also capable of transferring his knowledge to others which is a rare feature in the field of IT. He makes a point of not only solving issues but also of giving on the job training of his colleagues. A customer says " Robert has been a big influence on our technical staff and I have to come to know him as a brilliant specialist concerning Microsoft Products. He was Capable with his in-depth knowledge of Microsoft products to troubleshoot problems and develop our infrastructure to a higher level. I would certainly hire him again in the future. " Details of the Recommendation: "I have been coordinating with Robert implementing a very complex system. Although he was primarily a Microsoft infrastructure specialist; he was able to understand and debug .Net based complext Windows applications and websites. His input to improve performance of applications proved very helpful for the success of our project

One thought on “Powershell Network Load Balancing”

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.