Using Install-DbaInstance to install (and even uninstall) a SQL Server failover cluster instance #7447
andreasjordan
started this conversation in
Show and tell
Replies: 3 comments
-
Great stuff as always Andreas. I've been wanting to use |
Beta Was this translation helpful? Give feedback.
0 replies
-
Note as of 2022-03-16: This code was also updated today to use the new functionality of Install-DbaInstance. To uninstall "normal" instances in my lab, I currently use this code:
Yes, you have to change a lot to let it work in your environment... |
Beta Was this translation helpful? Give feedback.
0 replies
-
Good stuff, thanks so much! |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Last updated: 2022-03-16
Tested with dbatools version: 1.1.81
I just had to setup a failover cluster instance in a lab and used Install-DbaInstance for that.
Maybe you can grab some code from that for your problem. But this is not a super documented and robust solution - it works on my maschine, mabe not on your maschine.
What is my setup? I have two nodes SQLCN01 and SQLCN02 based on Windows Server 2016 with the local drive C: for the operating system. I have two disks (10 GB for Quorum, 50 GB for SQL Server) mounted to both nodes. The SQL Server sources are located on a fileshare.
So lets get started with importing the needed modules and setting up some variables:
We need the cluster software and I want the management software locally:
Get the 10 GB drive which is RAW and initialize, partition and format it:
Now we are ready to build the cluster. The test is optional but a good idea for the first run. I always like to have nice names for all the ressources, especially if you have more than one of a type.
I also like to test the cluster and the drive letter of the quorum - as sometimes it is not the correct letter. So here is some code you will have to adapt to your environment:
The next part is to grant the necessary rights to the computer account of the cluster to later add a computer account for the virtual computer for the SQL Server cluster instance. If you like to use a gui, use this website.
Now it is time to prepare the 50 GB disk for the SQL Server instance, wich will be added to the cluster and renamed in the last two lines:
Let's again test if the drive letter is the correct one on both nodes:
Now the cluster is up and running, time to install the SQL Server instance.
The first node needs the action "InstallFailoverCluster" and a lot of information. I tried to use as many parameters of Install-DbaInstance as possible and put the rest in the Configuration hashtable.
The second node needs the action "AddNode" and far less information:
And here is how these hashtables are uses, it's called "splatting" if you haven't heared of it yet:
Tip: Don't use -EnableException with Install-DbaInstance, as you would not get the details about the exception.
I still use the windows firewall in this lab, so I need firewall rules:
Let's test. Connect, failover and connect again:
You don't need the instance and the cluster anymore? Let's remove it...
Both nodes needs the action "RemoveNode" and only a little bit of information:
Both nodes are removed the same way. But one after the other, never at the same time:
I remove all the firewall rules I created:
Now it's time to remove the cluster. The computer accounts of both the cluster and the sql server network name still stay in the AD, so I remove them to not have any leftovers:
And I clean the disks to be able to start again from the top. In my case, the cluster leaves the disks in Offline state. Don't do this in production, always be sure you clean the correct disk. Don't blame me for an empty C: drive...
I've run this with SQL Server 2016, 2017 and 2019. Always with a named instance, but with some adaptations it should work with a default instance as well.
Beta Was this translation helpful? Give feedback.
All reactions