Installing, Configuring and Managing Windows Server Failover Cluster using PowerShell Part 1
In a previous tip on Install SQL Server 2008 on a Windows Server 2008 Cluster Part 2, I've seen how to install and configure a Windows Server 2008 Failover Cluster in preparation for installing a SQL Server 2008 failover clustered instance. This time, I wanted to use Windows PowerShell to install, configure and manage a Windows Server Failover Cluster from the command-line or remotely from my workstation. How do I do it?
With Windows PowerShell becoming a standard tool for scripting and automating tasks, we need to be more familiar with it when performing Windows administrative tasks. As you've seen in this tip on Installing SQL Server 2012 on Windows Server Core Using PowerShell, we can use it 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. Windows Server 2012 made it a lot easier with the release of Windows PowerShell 3.0 and its module autoloading feature. This means that we can run Failover Clustering cmdlets without having to import the FailoverClusters module.
This series of tips will walk you through installation, configuration and management of a Windows Server Failover Cluster using Windows PowerShell. The cmdlets that I will be using for the tips apply to both Windows Server 2008 R2 and Windows Server 2012. However, I will highlight those that are specific to Windows Server 2012. It's a good thing that the cmdlets are backwards compatible in that you can manage Windows Server 2008 R2 failover clusters using the FailoverClusters module for Windows Server 2012. For this series of tips, I will be using Windows Server 2012.
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 (this is the part where I say, "You need to be nice to your domain administrators" because these tasks require domain administrator privileges.) 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. I, myself, forget sometimes.
Validating Cluster Configuration
In this previous tip, we 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 our failover cluster. With less mouse-clicks and a shorter amount of time, we can perform the same task using Windows PowerShell with 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 that 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.
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 "CN=WINCLUSTER3,OU=Clusters,DC=TESTDOMAIN,DC=local" -Node WS-CLUSTER3,WS-CLUSTER4 -StaticAddress 172.16.0.193
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.
If you have clustered storage configured, you will see those as well in your newly created failover cluster.
In this tip, we have created a Windows Server Failover Cluster using Windows PowerShell. In the next tip, we will look at the other Failover Clustering PowerShell cmdlets to configure and manage our Windows Server Failover Cluster and the clustered resources running on top of it. We will keep our focus on running SQL Server clustered resources like a failover clustered instance and AlwaysOn Availability Groups.
- Review the previous tips on Install SQL Server 2008 on a Windows Server 2008 Cluster Part 1, Part 2, Part 3 and Part 4. This will help you map the Failover Clustering PowerShell cmdlets with their corresponding actions on the Failover Cluster Management console.
Last Updated: 2013-07-17
About the author
View all my tips