First step to get started with AutomatedLabs.

Who wants to spend a lot of time to set up a lab every time you need to test or verify something? I know that I am probably late to the party. Also most of the party has probably left for the coulds, however, not all of us are ready for that kind of excitement just yet and still deploy local labs.

Creating local labs is easier if you use the fantastic PowerShell module called AutomatedLab available on Github and Powershell Gallery. It allows you to set up some rather fancy lab templates and if we want to expand to the Azure cloud at any point, this tool can follow you and create the sky-labs as well!

By the way, I am assuming that Hyper-V is already installed and all prerequisites are met on your local system. Anyway, to get started, open Powershell as an admin and type in:

Install-Module AutomatedLab -AllowClobber

You also might need to change the execution policy, but make sure that you change it to policy you are comfortable with. I am comfortable with “RemoteSigned” on my system. (The AllowClobber switch is required because some cmdlets in PSLog are overwriting existing cmdlets to redirect verbose and debug messages into a test log.)

You can also just save the module to your drive, go through the code at your leisure and import it later.

Save-Module AutomatedLab -Path c:\Users\Userx\Desktop\al\
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned
Import-Module AutomatedLab

When you want to import the module, make sure it is in a folder where PowerShell actually looks. You can find the default folders it searches in by checking:

$env:PSModulePath -split ';'

Before you start creating VMs, make sure that the LabSources folder is created. By running a single command you can create the necessary structure and download the needed files automatically.

New-LabSourcesFolder -Drive c

The command above will create a LabSources folder on your C-drive, as shown below.

The default content of the LabSources folder that is created.

Place the ISOs you want to use for OS and applications in the “ISOs”-folder. I put “Windows Server 2019 Evaluation Version” and “SQL Server 2019 Developer Edition” ISOs in that folder. Any tools you want on all VMs, just place it in the “Tools”-folder, and it will be copied to any new VM.

The contents of the folders in c:\Labsources\ISOs.

Further below is a script which helps me to create a test-lab quickly. After you provide a lab-name, it will do a few assumptions like the ISOs filepaths.

The script will create a DC with a domain called, it will create a couple of SQL Sever 2019 which are part of the domain and is set up with service accounts of the domain. It will also add the WorldWideImporter’s database.

You can see the details of the script below, which I recommend that you copy into Visual Studio Code, or Windows Powershell ISE, and read through it before you blindly run it as administrator.

$LabName = Read-Host 'Lab-name?'
$LabPath = "C:\AutomatedLab-VMs"
if (Test-Path $LabPath) {
else {
    Write-Host "Creating folder $LabPath..."
    New-Item -Path $LabPath -ItemType Directory
New-LabDefinition -Name $LabName -DefaultVirtualizationEngine HyperV -VmPath $LabPath
Add-LabIsoImageDefinition -Name SQLServer2019 -Path C:\LabSources\ISOs\SQL\en_sql_server_2019_developer_x64.iso
$PSDefaultParameterValues = @{
    'Add-LabMachineDefinition:DomainName' = ""
    'Add-LabMachineDefinition:OperatingSystem' = "Windows Server 2019 Datacenter Evaluation (Desktop Experience)"
$DBrole = Get-LabMachineRoleDefinition -Role SQLServer2019 @{
    Features = 'SQL,Tools'
    InstanceName = 'SQL2019'
    SQLSvcAccount = 'lab\SQLSvc'
    SQLSvcPassword = 'Somepass1'
    AgtSvcStartupType = 'Automatic'
    AgtSvcAccount = 'lab\AgentSvc'
    AgtSvcPassword = 'Somepass1'
    InstallSampleDatabase = 'true'
Add-LabMachineDefinition -Name $LabName-DC01 -Roles RootDC
Add-LabMachineDefinition -Name $LabName-SQL01 -Roles $DBrole -Memory 1GB -MinMemory 512MB -MaxMemory 3GB
Add-LabMachineDefinition -Name $LabName-SQL02 -Roles $DBrole -Memory 1GB -MinMemory 512MB -MaxMemory 3GB
Show-LabDeploymentSummary -Detailed

Sometimes I need a CA, which you can easily add to the lab:

Add-LabMachineDefinition -Name CA1 -Roles CaRoot

That should be it for this time. If you need more sample databases, I have a few links below where Microsoft publishes their examples.

PS. Do not add this to a production system – I should not have to remind you that labs does not belong anywhere in production…