PowerShell for Network Load Balancing (NLB) in Windows Server 2008 R2

Hi Cluster Fans,


In Windows Server 2008 R2 (“R2”) we are introducing PowerShell as the new scripting language for clustering technologies.  PowerShell with Network Load Balancing (NLB) will replace NLB.exe and WLBS.exe.  The Windows Server 2008 R2 release is the last release for NLB.exe and WLBS.exe.  This means it will still be available for use so it doesn’t break legacy scripts, but no improvements have been made so NLB.exe and WLBS.exe will be completely removed in the next release of Windows Server.  Do not worry – you will love PowerShell with its numerous benefits over standard command line interfaces, including easily customizable scripts and the dynamic use of variables. 


In Windows Server 2008 R2, PowerShell can also be run on Server Core machines.  Using PowerShell on a Core NLB cluster, you can directly create and manage your NLB cluster, without needing to manage the Core node through a UI-based remote machine. 



This blog post will provide an overview of PowerShell with Network Load Balancing.  Also try out PowerShell for Failover Clustering.





How do I get R2 Beta?


                The Windows Server 2008 R2 Beta build will be available shortly for deployment and testing.  There are numerous ways to get the Windows Server 2008 R2 Beta build which includes Network Load Balancing.  If you work for an organization which partners with Microsoft, try contacting your Technology Account Manager (TAM) to see if they can provide you with access.  If your organization is enrolled in the Technology Adoption Program (TAP) you may also have access through this channel.  Others may enroll in the Microsoft Connect program (http://connect.microsoft.com/) to receive access to major builds.





We want your feedback!


PowerShell is going to be the cluster scripting language for the future – and you have the opportunity to influence its design and use for the next decade during the Beta feedback period.  Some high-level areas of feedback for the PowerShell commands (cmdlets) which we are looking for include the following:


·         Was it easy to find the cmdlet you wanted?


·         Are the parameters consistent between cmdlets?


·         Is the in-box help and example useful?


·         Has the PowerShell utility met your scripting needs?


·         Was there a cmdlet which did something different than you expected from its name or description?


·         Anything else?



We encourage you to provide feedback through the appropriate channels on the Microsoft Connect site, through your TAM, or TAP Program Manager.  You may also email your feedback to us via the Email link in the upper left corner of this page.





Running Network Load Balancing with PowerShell


The name of the NLB module is NetworkLoadBalancingClusters.


 


[Update: 10/5/2009] For the Windows Server 2008 R2 RTM release of the product you may access PowerShell management, launch as an Administrator and load ALL of your PowerShell modules automatically by selecting: Start à Administrator Tools à Windows PowerShell Modules.


 


This section provides instructions for running NLB with PowerShell.


·         Loading PowerShell with NLB can be done in two ways:


1.       Open Network Load Balancing PowerShell Management from the shortcut in Administrative Tools



            PowerShellNLB 


2.       Open PowerShell on your machine through right-clicking and selecting Run as administrator


§  Load the module with the command: Import-Module NetworkLoadBalancingClusters



Network Load Balancing PowerShell Cmdlets


Cmdlets (“command-lets”) form the basis of the PowerShell instruction set.  The design goal was for feature parity between the Network Load Balancing Manager GUI and PowerShell, so any operation can be performed on both.  This includes the ability to create NLB clusters, manage nodes, manage VIP/DIP addresses, and manage port rules – things which were not achievable from the traditional CLI tools, nlb.exe/wlbs.exe. Additionally, through the cmdlet Get-NlbClusterDriverInfo, you get a lot of insights into the NLB driver.


 


To get a complete list of the cmdlets, run the following command: Get-Command -Module NetworkLoadBalancingClusters


 


The following is a list of NLB cmdlets for the Beta release.  Note that these are subject to change.


 


Name



Add-NlbClusterNode


Add-NlbClusterNodeDip


Add-NlbClusterPortRule


Add-NlbClusterVip


Disable-NlbClusterPortRule


Enable-NlbClusterPortRule


Get-NlbCluster


Get-NlbClusterDriverInfo


Get-NlbClusterNode


Get-NlbClusterNodeDip


Get-NlbClusterNodeNetworkInterface


Get-NlbClusterPortRule


Get-NlbClusterVip


New-NlbCluster


New-NlbClusterIpv6Address


Remove-NlbCluster


Remove-NlbClusterNode


Remove-NlbClusterNodeDip


Remove-NlbClusterPortRule


Remove-NlbClusterVip


Resume-NlbCluster


Resume-NlbClusterNode


Set-NlbCluster


Set-NlbClusterNode


Set-NlbClusterNodeDip


Set-NlbClusterPortRule


Set-NlbClusterPortRuleNodeHandlingPriority


Set-NlbClusterPortRuleNodeWeight


Set-NlbClusterVip


Start-NlbCluster


Start-NlbClusterNode


Stop-NlbCluster


Stop-NlbClusterNode


Suspend-NlbCluster


Suspend-NlbClusterNode


 


 


Help Documentation


PowerShell for NLB certainly has a lot of functionality, but to improve usability, extensive help and examples are built right into the utility.  Please refer to this in-box help when you use PowerShell.  This is also an area where we would like your feedback – please let us know if there is anything which you cannot find or you believe was misleading.


 


To get full help for a cmdlet: Get-Help <cmdlet_name> -Full


 


Let’s take a look at the Add-NlbClusterNode cmdlet:


PS C:\Windows\System32> Get-Help Add-NlbClusterNode –Full


 


NAME


    Add-NlbClusterNode


 


SYNOPSIS


    Adds a new node to the NLB cluster.


 


SYNTAX


    Add-NlbClusterNode [-Force] [-HostName <string>] -InterfaceName <string> [-NewNodeName] <string> [-NewNodeInterface] <string> [<CommonParameters>]


    Add-NlbClusterNode [-Force] -InputObject <Cluster[]> [-NewNodeName] <string


    > [-NewNodeInterface] <string> [<CommonParameters>]


 


DETAILED DESCRIPTION


    The Add-NlbClusterNode cmdlet adds a new host to the NLB cluster. Once the new host settings are circulated through all cluster hosts, the new cluster host will be in a running state in the cluster.


    This operation changes the configuration on all cluster nodes. As a result, the NLB cluster will have to restart the convergence process on all nodes to guarantee that configuration changes have been applied on all nodes and that a consistent state is reached. Any additional operations on the NLB cluster should not be initiated until all cluster nodes have completed the convergence process and are back to the converged state. To check the state of all cluster nodes, use the Get-NlbClusterNode cmdlet. If a configuration change results in the cluster nodes remaining in perpetual convergence, refer to the event log to resolve the configuration inconsistency between the cluster nodes.


 


PARAMETERS


    -Force [<SwitchParameter>]


        Performs the operation without prompting for confirmation. By default this operation will ask for confirmation from the user before proceeding.


        Required?                    false


        Position?                    named


        Default value


        Accept pipeline input?       false


        Accept wildcard characters?  false


    -HostName <string>


        Specifies the name of the host which is part of the cluster to run this cmdlet against. If this parameter is omitted or if “-HostName .” is used the local cluster is assumed. [Alias: hn]


        Required?                    false


        Position?                    named


        Default value


        Accept pipeline input?       false


        Accept wildcard characters?  false


    -InputObject <Cluster[]>


        Specifies the cluster to add the node to.


        Required?                    true


        Position?                    named


        Default value


        Accept pipeline input?       true (ByPropertyName)


        Accept wildcard characters?  false


    -InterfaceName <string>


        Specifies the interface where NLB is bound. This is the interface which is part of the cluster to run this cmdlet against.


        Required?                    true


        Position?                    named


        Default value


        Accept pipeline input?       false


        Accept wildcard characters?  false


    -NewNodeInterface <string>


        Specifies the interface name on the new cluster node. [Alias: ni]


        Required?                    true


        Position?                    2


        Default value


        Accept pipeline input?       false


        Accept wildcard characters?  false


    -NewNodeName <string>


        Specifies the name of the new cluster node. [Alias: nn]


        Required?                    true


        Position?                    1


        Default value


        Accept pipeline input?       false


        Accept wildcard characters?  false


    <CommonParameters>


        This cmdlet supports the common parameters: -Verbose, -Debug,


        -ErrorAction, -ErrorVariable, -WarningAction, -WarningVariable, -OutBuffer and -OutVariable. For more information, type, “get-help about_commonparameters”.


INPUT TYPE


    Microsoft.NetworkLoadBalancingClusters.PowerShell.Cluster


RETURN TYPE


    Microsoft.NetworkLoadBalancingClusters.PowerShell.Node


NOTES


    ————————– EXAMPLE 1 ————————–


    C:\PS>Get-NlbCluster node1 | Add-NlbClusterNode -NewNodeName node2 -NewNode


    Interface vlan-3


    Name                State               Interface           HostID


    —-                —–               ———           ——


    node2               Converged           vlan-3              2


    Description


    ———–


    This command adds host node2 to the cluster on node1.


RELATED LINKS


    Get-NlbClusterNode


    Remove-NlbClusterNode


    Resume-NlbClusterNode


    Set-NlbClusterNode


    Stop-NlbClusterNode


    Suspend-NlbClusterNode


 


 


To get full help for all NLB cmdlets: Get-Command -Module NetworkLoadBalancingClusters | %{ Get-Help $_.Name -Full }


 


 


Example


Here’s a sample PowerShell script where I create an NLB cluster, add nodes to the cluster, manage the port rules, and get some information about the cluster and port rules.


 


# Create the NLB cluster on the local machine


New-NlbCluster -InterfaceName vlan-4 -ClusterName ahmedb


nlbclus1 -ClusterPrimaryIP 4.0.9.99 -SubnetMask 255.0.0.0



# Add a node to the cluster


Get-NlbCluster | Add-NlbClusterNode -NewNodeName node2 -NewNodeInterface vlan-4


 


# Get some information about the NLB cluster


Get-NlbCluster


Get-NlbClusterNode


Get-NlbClusterVip


Get-NlbClusterNodeDip


Get-NlbClusterPortRule



 


# Get rid of the default port rule


Get-NlbClusterPortRule | Remove-NlbClusterPortRule


 


# Add specific port rules


Get-NlbCluster | Add-NlbClusterPortRule -StartPort 80 -EndPort 80 -Affinity None


Get-NlbCluster | Add-NlbClusterPortRule -StartPort 443 -EndPort 443


 


 


Good luck with your PowerShell and NLB deployments and please send us your feedback!


 


Thanks,


Symon Perriman, Program Manager


Ahmed Bisht, Senior Program Manager


Clustering & High Availability