If you have a Hyper-V host running Windows Server Datacenter edition (in lab environments, typically this would come from a Visual Studio/MSDN subscription), one of the nice features that you can leverage is Automatic Virtual Machine Activation. The problem is that it’s not automatic. When you create a new Windows Server VM, you’ll see that it’s not activated:
Fortunately, it’s trivial to inject the needed product key to get the OS to activate. The key you need depends on the OS version and Windows Server SKU that you are running, but the documentation lists those clearly. Since I’m running Windows Server 2019 Datacenter in my VMs (might as well use Datacenter for the VMs since you can run as many Windows Server VMs of any SKU when you have a Datacenter host), I just need to use the H3RNG-8C32Q-Q8FRX-6TDXV-WMBMW key:
Presto, the product key is installed and the Windows Server 2019 Datacenter VM activates immediately (and “automatically”).