• ESXTOP
  • About
  • Guides
    • SQL Server 2016 Scripted Powershell Installation
    • Powershell Failover Cluster Install – SQL Server AAG or WSFC
    • AAG Add – Powershell
  • Travel Tips

Powershell Failover Cluster Install – SQL Server AAG or WSFC

October 4, 2019

In my previous post, I bolted some data in which we handle the install of SQL server via Powershell, this will be an on going series.  Below is some powershell I wrote to install the features for FCI and also add the nodes, etc.  By the end of this series I will combine all of these for an end to end deployment or one can decouple and use pieces they see fit.

PowerShell
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<#
 
$Node1=Read-Host "Enter ClusterNode1 Name"
$Node2=Read-Host "Enter ClusterNode2 Name"
$ClusterName=Read-Host "Enter new Cluster Name"
$ClusterIP=Read-Host "Enter new Cluster IP"
 
#Trimming white spaces
$Node1=$Node1.trim()
$Node2=$Node2.trim()
$ClusterName=$ClusterName.trim()
$ClusterIP=$ClusterIP.trim()
 
#Install the Failover Clustering feature and the management tools.The installation of the Failover Clustering feature does not require a reboot.
Install-WindowsFeature -Name Failover-Clustering -IncludeManagementTools -ComputerName $Node1
 
#install the Failover Clustering feature and the management tools in secondary node
Install-WindowsFeature -Name Failover-Clustering -IncludeManagementTools -ComputerName $Node2
 
#Continue only if the feature is installed in node2
#$Installstate=Get-WindowsFeature -Name Failover* -ComputerName -Node2 | Where Installed
 
$loop_control = 0
$timeout=20
 
do {
          $Installstate=Get-WindowsFeature -Name Failover* -ComputerName $Node1 | Where Installed
         Start-Sleep 30
$loop_control++
     } until ( ($Installstate -ne $null) -or ($loop_control -gt $timeout) )
 
 
if ($loop_control -gt $timeout){
Write-host "Check if the fail over cluster feature is installed properly on $Node1 and re run the script"
 
}
 
do {
          $Installstate=Get-WindowsFeature -Name Failover* -ComputerName $Node2 | Where Installed
         Start-Sleep 30
$loop_control++
     } until ( ($Installstate -ne $null) -or ($loop_control -gt $timeout) )
 
 
if ($loop_control -gt $timeout){
Write-host "Check if the fail over cluster feature is installed properly on $Node2 and re run the script"
 
}
 
 
 
else {
 
#Import Failover Clustering module
Write-host "Importing Failover Clustering module"
 
Import-Module FailoverClusters
#creating new cluster with static ip address
 
Write-host "creating new cluster "$ClusterName" with static ip address"$ClusterIP" and nodes "$Node1" "$Node2".. "
New-Cluster -Name $ClusterName -Node $Node1,$Node2 -StaticAddress $ClusterIP -NoStorage
 
#Inspect available cluster disks
#Write-host "available cluster disks"
#Get-ClusterAvailableDisk -Cluster $ClusterName
 
#Configure cluster quorom
Write-host "Configuring the quorum using FSW for cluster"$ClusterName".. "
Set-ClusterQuorum -FileShareWitness '\\JUMPHOST-AK\Share' -Cluster $ClusterIP
 
#Create cluster validation report
Write-host "preparing to run cluster validation report"
Test-Cluster -Node $Node1,$Node2
 
}

powershellsql serverwindows
Share

Microsoft  / Powershell  / SQL Server

Leave A Reply


Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *




© Copyright LetsBlog Theme Demo - Theme by ThemeGoods