Installing, Configuring and Managing Windows Server Failover Cluster using PowerShell Part 1

By:   |   Comments (8)   |   Related: 1 | 2 | 3 | 4 | > Clustering


Problem

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?

Solution

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

Installing the Windows Failover Clustering Feature

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

Validating Cluster Configuration

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.

Windows Failover Cluster Validation Wizard

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.

install SQL Server failover clustered instances on this cluster

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 

Creating the Windows Server Failover Cluster

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.

New in Windows Server 2012 is the ability to create a Windows Server Failover Cluster in an Active Directory organizational unit

Using Windows PowerShell:

New-Cluster -Name "CN=WINCLUSTER3,OU=Clusters,DC=TESTDOMAIN,DC=local" -Node WS-CLUSTER3,WS-CLUSTER4 -StaticAddress 172.16.0.193 

Using Windows PowerShell:

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 *

Verify the Windows Server Failover Cluster Configuration

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

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.

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.

Next Steps
  • 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.


sql server categories

sql server webinars

subscribe to mssqltips

sql server tutorials

sql server white papers

next tip



About the author
MSSQLTips author Edwin Sarmiento Edwin M Sarmiento is a Microsoft SQL Server MVP and Microsoft Certified Master from Ottawa, Canada specializing in high availability, disaster recovery and system infrastructures.

This author pledges the content of this article is based on professional experience and not AI generated.

View all my tips



Comments For This Article




Thursday, March 7, 2019 - 9:16:37 PM - bass_player Back To Top (79210)

Darren,

What's the purpose of running PowerShell remotely on non-domain-joined servers? Is it for on-going management and support? Is it for intial configuration?

You will need to configure PowerShell Remoting on a non-domain-joined machine to get this to work and allow your credential to be passed to the remote machine. 


Friday, February 22, 2019 - 4:59:55 AM - Darren Back To Top (79090)

Hi.

How should cluster creation command (New-Cluster) be run if initiated from a remote computer against two non-domain joined Win2016 servers? I’ve tried the below, but not working… I’ve tried using start-process to initiate. I’ve tried using credSSP, but not having any joy. The creds are local admins on both cluster nodes (same username, same password). WSFC Windows Feature is installed on both nodes. Any assistance is appreciated.

Invoke-Command -ComputerName $servers[0] -Credential $myCreds -ScriptBlock {New-Cluster -Name $using:clusterName -Node $using:node1,$using:node2 -AdministrativeAccessPoint DNS -StaticAddress $using:clusterIP -NoStorage }

Error received is:

There was an error adding node ‘NODE2’ to the cluster

You do not have administrative privileges on the server ‘NODE2’.

Attempted to perform an unauthorized operation.

+ CategoryInfo : PermissionDenied: (:) [New-Cluster], ClusterCmdletException

+ FullyQualifiedErrorId : UnauthorizedAccess,Microsoft.FailoverClusters.PowerShell.NewClusterCommand

Thanks

Darren


Thursday, April 17, 2014 - 8:20:29 AM - Jitendra More Back To Top (30090)

It is very helpful...

 

Thanks & Regards

Jtendra More


Monday, November 11, 2013 - 3:49:46 PM - Prince Back To Top (27461)

Very helpful.

 

Thanks!


Friday, August 9, 2013 - 1:42:01 PM - Jeremy Kadlec Back To Top (26194)

Edwin,

Congrats on your 70th tip!

Thank you,
Jeremy Kadlec
Community Co-Leader


Monday, August 5, 2013 - 1:29:12 AM - vkp Back To Top (26106)

hI! vERY USEFUL INFORMATION,THANK U EDWIN


Monday, July 29, 2013 - 12:38:55 PM - Chris Presley Back To Top (26051)

Great article Edwin!


Wednesday, July 17, 2013 - 8:42:50 AM - DavidS Back To Top (25876)

Great information.

 















get free sql tips
agree to terms