With Windows PowerShell becoming a standard tool for scripting and automating tasks, IT professionals need to be more familiar with it when performing Windows administrative tasks. PowerShell can be used to provision a Windows Server machine from the ground up in preparation for installing SQL Server 2012. Windows Server Failover Clustering is no exception. Since Windows Server 2008 R2, Windows PowerShell support has been made available thru the FailoverClusters module by running the Import-Module cmdlet. It has been made much easier now through Windows Server 2012 R2 because of the autoloading feature found in Windows PowerShell 4.0. Failover Clustering cmdlets can now operate without having to import the FailoverClusters module.
 
This Step-By-Step will walk you through installation, configuration and management of a Windows Server Failover Cluster using Windows PowerShell. The cmdlets used in this post apply to both Windows Server 2008 R2 and Windows Server 2012 R2. With the cmdlets being backwards compatible, one could manage Windows Server 2008 R2 failover clusters using the FailoverClusters module for Windows Server 2012.
 
 
Step 1: Installing the Windows Failover Clustering Feature

 
Similar to Windows Server 2008, the Failover Clustering feature is not installed by default on Windows Server 2012. We need to install it prior to creating a Windows Server Failover Cluster. Keep in mind that in order to install and configure a Windows Server Failover Cluster, you need to be a member of the local Administrators group on all of the servers that will act as nodes in your failover cluster. In addition, you need to have the Create Computer Objects and Read All Properties permissions in the organizational unit (OU) that you intend to create your Windows Server Failover Cluster as defined in this TechNet article. You also need to run the Windows PowerShell command shell using the Run as Administrator option. To install the Failover Clustering feature using Windows PowerShell,

Install-WindowsFeature -Name Failover-Clustering –IncludeManagementTools


 
The –IncludeManagementTools switch of the Install-WindowsFeature cmdlet specifies installation of all applicable management tools for the installed role or feature. This includes the MMC snap-in and the Windows PowerShell module associated with it. And, as a reminder, be sure to run this on all of the servers that will act as nodes in your failover cluster.
 
 
Step 2: Validating Cluster Configuration

Previously, an IT admin had to open up the Failover Cluster Management console and run the Failover Cluster Validation Wizard to validate the servers that will act as nodes in the failover cluster. With less mouse-clicks and a shorter amount of time, this same task can now be performed using Windows PowerShell and the Test-Cluster cmdlet. In the command below, I am passing the hostnames of the servers that will act as nodes in my failover cluster.

Test-Cluster -Node WS-ALWAYSON-AG1, WS-ALWAYSON-AG2

 
 
The command above is similar to initiating the Windows Failover Cluster Validation Wizard and running all the tests - storage, network, inventory, cluster configuration, etc. The next steps prior to building your Windows Server Failover Cluster will depend on how you intend to use it - either for a Hyper-V cluster, for a SQL Server failover clustered instance or for Availability Groups. In my case, since I am using the Windows Server Failover Cluster with SQL Server 2012 AlwaysOn Availability Groups, the results produced storage and network warnings since I'll only be using local storage instead of clustered ones. For this case, I can choose to ignore those warnings.
 

 
If you intend to install SQL Server failover clustered instances on this cluster, be sure to resolve all storage and network-related issues before creating the cluster. In the screenshot below, I ran the Test-Cluster cmdlet on servers that had clustered storage configured for use with a SQL Server failover clustered instance. With the clustered storage and network properly configured, the failover cluster validation test returns successful results.
 
 
 
Note: This will also generate a Failover Cluster Validation report that you can use for documentation or as a checklist to address the issues reported. The MHT file will be generated on all of the servers that you have included in the cluster validation test and stored on the C:\Windows\Cluster\Reports folder or the %USERPROFILE%\AppData\Local folder as specified in the output of the Test-Cluster cmdlet.
 
 
S
tep 3: Creating the Windows Server Failover Cluster

To create the Windows Server Failover Cluster, we will use the New-Cluster cmdlet. We will pass the hostnames of the servers that will act as nodes in the failover cluster, the virtual server name and its corresponding virtual IP address.

New-Cluster -Name WINCLUSTER2 -Node WS-ALWAYSON-AG1, WS-ALWAYSON-AG2 -StaticAddress 172.16.0.192


 
Again, the switches that you use with the New-Cluster cmdlet will depend on the configuration of your Windows Server Failover Cluster. For example, if you intend to intend to use DHCP for your virtual IP address, you can remove the -StaticAddress switch, similar to the command below. This assumes that your network cards are configured with dynamic IP addresses.

 

New-Cluster -Name WINCLUSTER2 -Node WS-ALWAYSON-AG1, WS-ALWAYSON-AG2

 

If you plan on installing and configuring a SQL Server multi-subnet failover clustered instance similar to this tip or a multi-subnet SQL Server 2012 AlwaysOn Availability Group, you can specify multiple virtual IP addresses with the -StaticAddress switch, similar to the command below. In this example, we can have an Availability Group configuration that has 2 nodes in different subnets.

 

New-Cluster -Name WINCLUSTER2 -Node WS-ALWAYSON-AG1, WS-ALWAYSON-AG2 -StaticAddress 172.16.0.192, 192.168.0.192

 

New in Windows Server 2012 is the ability to create a Windows Server Failover Cluster in an Active Directory organizational unit (OU) that is different than the ones that the cluster nodes are in. This feature made it easy for cluster administrators to create new Windows Server Failover Clusters in a restrictive Active Directory environment. The screenshot below shows how it looks when using the Create Cluster Wizard. This will create the cluster in the Clusters OU in the TESTDOMAIN.local domain. 
 

 
Using Windows PowerShell:

New-Cluster -Name WINCLUSTER2 -Node WS-ALWAYSON-AG1, WS-ALWAYSON-AG2 -StaticAddress 172.16.0.192, 192.168.0.192



Step 4: Verify the Windows Server Failover Cluster Configuration

 
Once the Windows Server Failover Cluster has been created, you can use the Get-Cluster cmdlet to display the information and configuration of your newly created cluster. I'm using the Format-List cmdlet to display all of the properties of the cluster.

 

Get-Cluster | Format-List *


 

 
We can then use the Get-ClusterResource cmdlet to display all of the cluster resources available in the cluster. Since we haven't installed and configured any cluster resources yet, the only ones we will see are the virtual server name and virtual IP address of the Windows Server Failover Cluster.

 

Get-ClusterResource


 

 
If you have clustered storage configured, you will see those as well in your newly created failover cluster.