This post takes the domain from Part 1 to a working availability group with a listener and a tested failover. Almost all of it runs from one PowerShell window on SQL01
Build the two SQL nodes
Run this on the laptop, in PowerShell as administrator.
$LabPath = 'C:\HyperV\Lab'
$SwitchName = 'Lab'
$IsoPath = 'C:\HyperV\ISO\WindowsServer2025.iso'
foreach ($VMName in 'SQL01', 'SQL02') {
New-VM -Name $VMName -Generation 2 -Path $LabPath `
-MemoryStartupBytes 6GB `
-NewVHDPath "$LabPath\$VMName\$VMName.vhdx" -NewVHDSizeBytes 80GB `
-SwitchName $SwitchName
Set-VM -Name $VMName -ProcessorCount 4 -StaticMemory
Add-VMDvdDrive -VMName $VMName -Path $IsoPath
Set-VMFirmware -VMName $VMName -FirstBootDevice (Get-VMDvdDrive -VMName $VMName)
Start-VM $VMName
}
The SQL nodes get fixed memory, because SQL Server behaves more predictably that way. I first sized them at 8 GB each, and the second node refused to start with “Unable to allocate 8192 MB of RAM”. At 6 GB each, the whole lab uses about half of the laptop’s 32 GB.
Install Windows Server on both nodes as in Part 1. Then run this inside SQL01:
hostname # a generated name such as WIN-XXXXXXXXXXX
New-NetIPAddress -InterfaceAlias 'Ethernet' -IPAddress 10.10.10.11 -PrefixLength 24 -DefaultGateway 10.10.10.1
Set-DnsClientServerAddress -InterfaceAlias 'Ethernet' -ServerAddresses 10.10.10.10
Resolve-DnsName lab.local # expect 10.10.10.10
Add-Computer -DomainName 'lab.local' -NewName 'SQL01' -Credential 'LAB\Administrator' -Restart
SQL02 gets the same block with 10.10.10.12 and SQL02. Both nodes use the domain controller for DNS, which is what lets them find the domain.
Create the Windows cluster
An availability group sits on top of a Windows Server failover cluster. Run this from SQL01, signed in as LAB\Administrator. The local administrator account cannot create the cluster’s objects in the domain.
hostname # SQL01
whoami # lab\administrator
Invoke-Command -ComputerName 'SQL01', 'SQL02' -ScriptBlock {
Install-WindowsFeature Failover-Clustering -IncludeManagementTools
} | Format-Table PSComputerName, Success, RestartNeeded
Test-Cluster -Node 'SQL01', 'SQL02'
New-Cluster -Name 'SQLCLUSTER' -Node 'SQL01', 'SQL02' -StaticAddress 10.10.10.20 -NoStorage
Set-ClusterQuorum -FileShareWitness '\\DC01\Witness'
The validation report will warn that the nodes share only one network and have no shared disks. Both are expected here. -NoStorage is deliberate: an availability group keeps its own copy of the data on each node, so there are no shared disks to add.
Check the result:
Get-ClusterNode
Get-ClusterQuorum
Resolve-DnsName SQLCLUSTER
Both nodes should be Up, the quorum resource should be the file share witness, and the cluster name should resolve to 10.10.10.20.
Install SQL Server unattended
SQL Server 2025 splits the old Developer edition in two. Enterprise Developer is the one to use, because Standard Developer limits availability groups to the basic kind. Both are free for non-production use from the SQL Server downloads page.
Attach the ISO from the laptop:
$SqlIso = 'C:\HyperV\ISO\SQLServer2025-EntDev.iso'
'SQL01', 'SQL02' | ForEach-Object { Set-VMDvdDrive -VMName $_ -Path $SqlIso }
Then run this inside each node, signed in as LAB\Administrator. It prompts once for the service account password and runs silently for 10 to 15 minutes.
hostname # SQL01 or SQL02
$svc = Get-Credential -UserName 'LAB\svc-sql' -Message 'SQL service account password'
$svcPw = $svc.GetNetworkCredential().Password
$dvd = (Get-Volume | Where-Object DriveType -eq 'CD-ROM').DriveLetter
$setupArgs = @(
'/Q', '/ACTION=Install', '/IACCEPTSQLSERVERLICENSETERMS',
'/FEATURES=SQLENGINE', '/INSTANCENAME=MSSQLSERVER',
'/SQLSVCACCOUNT=LAB\svc-sql', "/SQLSVCPASSWORD=$svcPw",
'/AGTSVCACCOUNT=LAB\svc-sql', "/AGTSVCPASSWORD=$svcPw", '/AGTSVCSTARTUPTYPE=Automatic',
'/SQLSYSADMINACCOUNTS=LAB\Administrator',
'/TCPENABLED=1', '/SQLSVCINSTANTFILEINIT=True', '/UPDATEENABLED=False'
)
& "${dvd}:\setup.exe" @setupArgs
"Setup exit code: $LASTEXITCODE"
Remove-Variable svcPw
New-NetFirewallRule -DisplayName 'SQL Server (TCP 1433)' -Direction Inbound -Protocol TCP -LocalPort 1433 -Action Allow
New-NetFirewallRule -DisplayName 'SQL AG endpoint (TCP 5022)' -Direction Inbound -Protocol TCP -LocalPort 5022 -Action Allow
An exit code of 0 means success. Port 1433 carries client connections, and port 5022 is the channel the two nodes use to replicate data. To confirm the edition, read the setup summary:
Get-Service MSSQLSERVER, SQLSERVERAGENT
Get-Content 'C:\Program Files\Microsoft SQL Server\170\Setup Bootstrap\Log\Summary.txt' |
Select-String 'Final result', 'Installation edition'
Build the availability group with dbatools
dbatools is a community PowerShell module for SQL Server. It turns a long sequence of wizard pages into a handful of commands. Run everything in this section from SQL01.
Install-PackageProvider -Name NuGet -Force
Install-Module dbatools -Scope AllUsers -Force
Set-DbatoolsInsecureConnection -SessionOnly
Enable-DbaAgHadr -SqlInstance 'SQL01', 'SQL02' -Force
Set-DbatoolsInsecureConnection tells dbatools to trust the nodes’ self-signed certificates. That is a lab shortcut, and it applies only to the current window. Enable-DbaAgHadr -Force switches on the Always On feature and restarts the SQL service so it takes effect.
Next, create a test database. A database must be in full recovery and have a full backup before it can join an availability group.
New-DbaDatabase -SqlInstance 'SQL01' -Name 'LabDB' -RecoveryModel Full
Backup-DbaDatabase -SqlInstance 'SQL01' -Database 'LabDB'
Then create the group and its listener:
$ag = @{
Primary = 'SQL01'
Secondary = 'SQL02'
Name = 'LabAG'
Database = 'LabDB'
ClusterType = 'Wsfc'
AvailabilityMode = 'SynchronousCommit'
FailoverMode = 'Automatic'
SeedingMode = 'Automatic'
Confirm = $false
}
New-DbaAvailabilityGroup @ag
Add-DbaAgListener -SqlInstance 'SQL01' -AvailabilityGroup 'LabAG' -Name 'AGLISTENER' `
-IPAddress 10.10.10.21 -SubnetMask 255.255.255.0 -Port 1433
Three of those settings carry the design:
- Synchronous commit means a transaction is not confirmed until both nodes have it, so a failover loses no data.
- Automatic failover lets the cluster move the group without anyone stepping in.
- Automatic seeding copies the database to SQL02 over the network, so no backup is restored there by hand.
The listener is the name applications connect to. It follows the primary, so nothing outside the cluster needs to know which node is in charge.
Verify and fail over
Get-DbaAgReplica -SqlInstance 'SQL01' | Format-Table Name, Role, AvailabilityMode, FailoverMode, ConnectionState
Get-DbaAgDatabase -SqlInstance 'SQL01' | Format-Table Name, SynchronizationState, IsJoined
Invoke-DbaQuery -SqlInstance 'AGLISTENER' -Query 'SELECT @@SERVERNAME AS PrimaryNode'
SQL01 should be the primary, SQL02 a connected secondary, and LabDB synchronized. The last query answers through the listener and names the node that served it.
Now move the group and ask again:
Invoke-DbaAgFailover -SqlInstance 'SQL02' -AvailabilityGroup 'LabAG' -Confirm:$false
Invoke-DbaQuery -SqlInstance 'AGLISTENER' -Query 'SELECT @@SERVERNAME AS PrimaryNode'
The same listener name now answers from SQL02. That one changed line of output is the point of the whole build.
Checkpoint the lab
The lab now has three machines that depend on each other, so checkpoint them as a set. Rolling back one domain or cluster member on its own leaves it out of step with the others.
Run this on the laptop.
$label = 'Part 2 complete'
Stop-VM -Name 'SQL01', 'SQL02'
Stop-VM -Name 'DC01'
Get-VM -Name 'DC01', 'SQL01', 'SQL02' | Checkpoint-VM -SnapshotName $label
Start-VM -Name 'DC01'
Start-Sleep -Seconds 90
Start-VM -Name 'SQL01', 'SQL02'
The domain controller stops last and starts first, because the cluster needs DNS and Active Directory before it can form. Give the nodes a few minutes after they start, then rerun the verification commands above to confirm LabDB is synchronized again.
To roll back, stop all three machines and restore the same label on each:
'DC01', 'SQL01', 'SQL02' | ForEach-Object { Restore-VMCheckpoint -VMName $_ -Name $label -Confirm:$false }
What I would tell someone starting this
- Check which window you are in. Hyper-V commands such as
Set-VMDvdDriveexist only on the host. “The term is not recognized” inside a virtual machine means the wrong window, not a broken install. - Size for the machine you are working on. The first memory plan fitted on paper and failed in practice.
- Name the shortcuts. Trusting self-signed certificates and running everything as a domain administrator are fine in a lab and wrong in production.
Where this leaves the lab
The lab now has a two-node availability group with automatic failover and a listener. Part 3 puts a live Power BI dashboard on top of it and powers off the primary node while the report is open.