# NAME: New-NlbCluster.ps1 # # AUTHOR: Robert Smit # EMAIL: robert.smit@aca-computers.nl # # COMMENT: Script to create a NLB-cluster. # # # You have a royalty-free right to use, modify, reproduce, and # distribute this script file in any way you find useful, provided that # you agree that the creator, owner above has no warranty, obligations, # or liability for such use. # # VERSION HISTORY: # 1.0 7.11.2010 - Initial release # ########################################################################### #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" #Set ExecutionPolicy Write-Host "Set ExecutionPolicy" -ForegroundColor yellow Set-ExecutionPolicy -scope LocalMachine RemoteSigned –force #Importing Microsoft`s PowerShell-modules Write-Host "Importing Microsoft`s PowerShell-modules" -ForegroundColor yellow ImportSystemModules #Add-WindowsFeature Write-Host "Add-WindowsFeature NLB" -ForegroundColor yellow Add-WindowsFeature NLB #Importing Microsoft`s PowerShell-module for administering NLB Clusters Write-Host "Importing Microsoft`s PowerShell-module for administering NLB Clusters" -ForegroundColor yellow Import-Module NetworkLoadBalancingClusters #function EndPSS { get-pssession | remove-pssession } Write-Host "function EndPSS { get-pssession | remove-pssession }" -ForegroundColor yellow function EndPSS { get-pssession | remove-pssession } endpss function EndPSS { get-pssession | remove-pssession } #Variables for creating the new cluster Write-Host "Variables for creating the new cluster" -ForegroundColor yellow $ClusterFqdn = Read-Host "Enter NLB cluster Name FQDN" $InterfaceName = Read-Host "Enter interface name for NLB-adapter" $ClusterPrimaryIP = Read-Host "Enter cluster primary IP" $ClusterPrimaryIPSubnetMask = Read-Host "Enter subnetmask for cluster primary IP" Write-Host "Choose cluster operation mode" Write-Host "1 - Unicast" Write-Host "2 - Multicast" Write-Host "3 - IGMP Multicast" switch (Read-Host "Enter the number for your chosen operation mode") { 1 {$OperationMode = "unicast"} 2 {$OperationMode = "multicastcast"} 3 {$OperationMode = "igmpmulticast"} default {Write-Warning "Invalid option, choose '1', '2' or '3'";return} } #Creating new cluster Write-Host "Creating NLB Cluster..." -ForegroundColor yellow New-NlbCluster -ClusterName $ClusterFqdn -InterfaceName $InterfaceName -ClusterPrimaryIP $ClusterPrimaryIP -SubnetMask $ClusterPrimaryIPSubnetMask -OperationMode $OperationMode #Removing default port rule for the new cluster Write-Host "Removing default port rule..." -ForegroundColor yellow Get-NlbClusterPortRule -HostName . | Remove-NlbClusterPortRule -Force #Adding port rules Add-NlbClusterPortRule -Protocol Tcp -Mode Multiple -Affinity Single -StartPort 80 -EndPort 80 -InterfaceName $InterfaceName | Out-Null Write-Host "Added port rule for http (tcp 80)" -ForegroundColor yellow Add-NlbClusterPortRule -Protocol Tcp -Mode Multiple -Affinity Single -StartPort 443 -EndPort 443 -InterfaceName $InterfaceName | Out-Null Write-Host "Added port rule for https (tcp 443)" -ForegroundColor yellow #Remove Old IP Remove-NlbClusterNodeDIP 1.1.1.1 -force Write-Host "Removed NLB Local IP" -ForegroundColor yellow #Adding additional cluster nodes based on user input Write-Host "Give Second NLB host" -ForegroundColor yellow $Node2Fqdn = Read-Host "Enter 2e NLB node" 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 Write-Warning "Before adding additional nodes, make sure that NLB are installed and the NLB-adapter are configured with a static IP-address on the remote node" $additionalnodes = Read-Host "Add additional nodes to the cluster? Y/N" if ($additionalnodes -like "y"){ do { $NodeFqdn = Read-Host "Enter FQDN for the additional node" $NewNodeInterface = Read-Host "Enter interface name for NLB-adapter on the additional node" Write-Host "Adding cluster node $NodeFqdn" -ForegroundColor yellow Get-NlbCluster -HostName . | Add-NlbClusterNode -NewNodeName $NodeFqdn -NewNodeInterface $NewNodeInterface $additionalnodes = Read-Host "Add additional nodes to the cluster? Y/N" } until ($additionalnodes -like "n") }