Skip to content

Instantly share code, notes, and snippets.

@rheid
Created May 8, 2015 10:36
Show Gist options
  • Save rheid/6e13667430d1d9d2644a to your computer and use it in GitHub Desktop.
Save rheid/6e13667430d1d9d2644a to your computer and use it in GitHub Desktop.
Setup Windows Server NLB
# Install Network Load Balancing and Tools
Write-Host "Install Network Load Balancing and Tools"
Add-WindowsFeature NLB, RSAT-NLB
Import-Module NetworkLoadBalancingClusters
# If the cluster hasn't been created yet then create it
if (!(Get-NlbCluster -HostName $clusterIpAddress -ErrorAction SilentlyContinue))
{
Write-Host "Creating NLB Cluster: $clusterName" -ForegroundColor yellow
# Create Cluster (default unicast)
New-NlbCluster -InterfaceName $interfaceName -ClusterName $clusterName -ClusterPrimaryIP $clusterIpAddress -SubnetMask $clusterSubnet
# Remove defaults
Write-Host "Removing default port rules" -ForegroundColor yellow
Get-NlbClusterPortRule | Remove-NlbClusterPortRule -Force
# Create port rules
Get-NlbCluster | Add-NlbClusterPortRule -StartPort 80 -EndPort 80 -Protocol TCP -Affinity None | Out-Null
Get-NlbCluster | Add-NlbClusterPortRule -StartPort 443 -EndPort 443 -Protocol TCP -Affinity None | Out-Null
}
else
{
Get-NlbCluster
}
# if this node isn't already a member of a cluster then add it
if(!(Get-NlbClusterNode -HostName $env:COMPUTERNAME))
{
# Add node to cluster
Write-Host "Adding node to cluster: $clusterName" -ForegroundColor yellow
Get-NlbCluster -HostName $clusterIpAddress | Add-NlbClusterNode -NewNodeName $env:COMPUTERNAME -NewNodeInterface $interfaceName
}
else
{
Get-NlbClusterNode
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment