In these articles, we’ll look at how to set up high availability on one or more databases with AlwaysOn functionality, using the « dbatools » PowerShell library.
To do this, we’ll need to create a Windows Server 2022 Virtual Machine, set up an active directory and two SQL server instances on two different servers, using Failover Clustering.

In this article you will learn :

  • How to activate Hyper-V feature
  • How to create and configure a Windows Server virtual machine

Activate Hyper-V feature

For this tutorial, we’re going to create our virtual machine with Hyper-V. To activate Hyper-V, run this Powershell command (to use Hyper-V, you need Windows 10/11 Enterprise, Pro or Education edition)

Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V -All
Hyper-V Feature

Create and configure a Windows Server virtual machine

Then download the Windows Server 2022 ISO file.
Link : Windows Server 2022 | Microsoft Evaluation Center

Place the ISO file in the directory of your choice

Download Windows Server 2022 file

Then run the powershell command below, changing the « Name » fields to the virtual machine name, « NewVHDPath » to the disk location and « Path » to the location of your ISO file.

New-VM -Name "VMWindowsServer" -SwitchName "Default Switch" 
-MemoryStartupBytes 4GB -Generation 1 -NewVHDPath "C:\TestWindowsServer\TestWindowsServer.vhdx" -NewVHDSizeBytes 20GB  
Add-VMDvdDrive -VMName "VMWindowsServer" -Path "C:\SERVER_EVAL_x64FRE_en-us.iso"

Now, we have create a Windows Server 2022 virtual machine so we will configure it.

We’re now going to launch our VM and configure Windows Server.

Select Windows Server 2022 Standard Evaluation (Desktop Experience)

Accept the terms of the license

Select « Custom » for the type of installation.

Then select « New » -> « Apply> -> « Next ».

Wait for the installation to finish and set the administrator password.

Once Windows Server has been installed, run the powershell commands below to create an external virtual switch so that our VM can access the Internet, and to add this switch to our VM.

New-VMSwitch -Name "External Switch" -NetAdapterName "Wi-Fi"
Add-VMNetworkAdapter -VMName "TestWindowsServer" -SwitchName "External Switch"

The scrennshot below shows that our new virtual switch has been created and added to our VM.

Hyper-V settings

Log on to your VM and execute the powershell command :

Set-NetFirewallProfile -Profile Domain,Public,Private -Enabled False

Or look for « Firewall » in the Windows menu.

Then click on « Windows Defender Firewall Properties » and set the « Firewall state » field to « Off » for the « Domain Profile », « Private Profile » and « Public Profile » tabs.

You’ve successfully create a Windows Server 2022 virtual machine and configured it with the right settings for future articles.

Conclusion

You now have your virtual machine ready to use, so you know how create a Windows Server 2022 Virtual Machine. This tutorial will help you create the three virtual machines we’ll need to implement high availability on SQL Server.
In the second part, we’ll look at how to install and configure an active directory.