AutomatedLab Setup and Basic AD Lab
Overview
AutomatedLab is a PowerShell module that builds lab environments on Hyper-V or Azure from a definition script. This post covers installing it and deploying a small Active Directory lab: one domain controller, two member servers and one Windows client, with outbound internet access through NAT on the Hyper-V host.
AutomatedLab is a different project from PSAutoLab. PSAutoLab is built on the Lability module, runs only in Windows PowerShell 5.1 and uses its own commands (Setup-Host, Setup-Lab). Nothing in this post applies to it.
To download the MSI installer please use this link - https://automatedlab.org/en/latest/
| VM | Operating system | Role | IP address |
|---|---|---|---|
| DC01 | Windows Server 2022 Standard (Desktop Experience) | Root domain controller and DNS | 192.168.10.10 |
| Srv01 | Windows Server 2022 Standard (Desktop Experience) | Member server | 192.168.10.21 |
| Srv02 | Windows Server 2022 Standard (Desktop Experience) | Member server | 192.168.10.22 |
| Client1 | Windows 10 Pro | Domain-joined client | 192.168.10.100 |
| Hyper-V host | - | NAT gateway | 192.168.10.1 |
Domain lab.local, network 192.168.10.0/24.
Requirements
| Item | Requirement |
|---|---|
| Host OS | Windows 8.1 / Windows Server 2012 R2 or later with Hyper-V (Windows client: Pro, Enterprise or Education) |
| PowerShell | Windows PowerShell 5.1 (.NET Framework 4.7.1) or PowerShell 7 |
| Rights | Local administrator on the host |
| Media | An ISO for each operating system in the lab, en-US recommended |
| Memory | Four VMs at 2 GB need 8 GB for the VMs alone, plus the host’s own use |
| Storage | SSD recommended; AutomatedLab reports problems on slow spinning disks |
Enable Hyper-V if it is not already on, then restart:
# Windows 10/11
Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V -All
# Windows Server
Install-WindowsFeature -Name Hyper-V -IncludeManagementTools -Restart
Install AutomatedLab
Run every command in this post from an elevated PowerShell session.
Option 1: PowerShell Gallery
The project documents this as the only way to install AutomatedLab for PowerShell 7.
Install-PackageProvider -Name NuGet -Force
Install-Module -Name AutomatedLab -SkipPublisherCheck -AllowClobber -Force
-SkipPublisherCheck is needed because AutomatedLab’s test module requires Pester 5, and installs fail on systems that only have Pester 3 (the version included with Windows).
Pre-answer the telemetry prompt, enable host remoting and create the LabSources folder:
[Environment]::SetEnvironmentVariable('AUTOMATEDLAB_TELEMETRY_OPTIN', 'false', 'Machine')
$env:AUTOMATEDLAB_TELEMETRY_OPTIN = 'false'
Enable-LabHostRemoting -Force
New-LabSourcesFolder -DriveLetter C
New-LabSourcesFolder creates C:\LabSources with its subfolders (ISOs, tools, scripts). Use another drive letter to keep ISOs on a larger disk.
Option 2: MSI Installer
Download AutomatedLab.msi from the project’s GitHub releases page and choose Typical or Complete. Both install the modules to C:\Program Files\WindowsPowerShell\Modules and create C:\LabSources. Custom lets LabSources go on another disk; the project advises leaving the module location at its default.
Use the Gallery instead if the lab will be run from PowerShell 7 (pwsh).
Confirm either install:
Get-Module AutomatedLab -ListAvailable | Select-Object Name, Version, ModuleBase
Updating
| Installed with | Update method |
|---|---|
Install-Module | Update-Module -Name AutomatedLab |
| MSI | Install the newer MSI from GitHub releases |
Update-Module only updates modules that were installed with Install-Module, so it cannot update an MSI install. ModuleBase from the command above shows where the module is installed.
Host Configuration
Copy the ISOs into C:\LabSources\ISOs, then list the operating systems AutomatedLab finds. The names used in the lab script must match this output exactly.
Get-LabAvailableOperatingSystem | Sort-Object OperatingSystemName | Format-Table OperatingSystemName, Version
Set the VM storage path. If the ISOs are not en-US (en-GB, for example), also stop AutomatedLab skipping them. The -FullName ... | Register-PSFConfig form keeps the settings across sessions and module updates.
Set-PSFConfig -FullName AutomatedLab.VmPath -Value '<VM_PATH>' -PassThru | Register-PSFConfig
Set-PSFConfig -FullName AutomatedLab.DoNotSkipNonNonEnglishIso -Value $true -PassThru | Register-PSFConfig
Get-PSFConfig -Module AutomatedLab | Where-Object Name -in 'VmPath', 'DoNotSkipNonNonEnglishIso' | Format-Table Name, Value
The setting name really is DoNotSkipNonNonEnglishIso, with “Non” twice. Its default is False.
Lab Definition Script
Save as Deploy-BasicLab.ps1 and replace <ADMIN_PASSWORD>. The password sits in plain text in the script, so use it for the lab only.
AutomatedLab has no NAT definition cmdlet, so the script builds an internal network and internet access is added on the host afterwards (Internet Access). $PSDefaultParameterValues applies the network, domain and memory to every Add-LabMachineDefinition call.
#Requires -Modules AutomatedLab
#Requires -RunAsAdministrator
# Lab settings
$LabName = 'BasicLab'
$DomainName = 'lab.local'
$AddressSpace = '192.168.10.0/24'
$AdminPassword = '<ADMIN_PASSWORD>'
# Must match Get-LabAvailableOperatingSystem output exactly
$ServerOS = 'Windows Server 2022 Standard (Desktop Experience)'
$ClientOS = 'Windows 10 Pro'
# Lab, credentials, network and domain
New-LabDefinition -Name $LabName -DefaultVirtualizationEngine HyperV
Set-LabInstallationCredential -Username Administrator -Password $AdminPassword
Add-LabVirtualNetworkDefinition -Name $LabName -AddressSpace $AddressSpace
Add-LabDomainDefinition -Name $DomainName -AdminUser Administrator -AdminPassword $AdminPassword
# Defaults for every machine
$PSDefaultParameterValues = @{
'Add-LabMachineDefinition:Network' = $LabName
'Add-LabMachineDefinition:DomainName' = $DomainName
'Add-LabMachineDefinition:Memory' = 2GB
}
# Machines
Add-LabMachineDefinition -Name DC01 -OperatingSystem $ServerOS -Roles RootDC -IpAddress '192.168.10.10'
Add-LabMachineDefinition -Name Srv01 -OperatingSystem $ServerOS -IpAddress '192.168.10.21'
Add-LabMachineDefinition -Name Srv02 -OperatingSystem $ServerOS -IpAddress '192.168.10.22'
Add-LabMachineDefinition -Name Client1 -OperatingSystem $ClientOS -IpAddress '192.168.10.100'
# Deploy
Install-Lab
Show-LabDeploymentSummary
Deploy and Verify
& 'C:\<SCRIPT_FOLDER>\Deploy-BasicLab.ps1'
Install-Lab creates the switch and VMs, installs the operating systems, promotes DC01 and joins the other machines to the domain. When it finishes:
Get-LabVM | Format-Table Name, OperatingSystem, DomainName
Get-LabVMStatus
Expected: four machines listed, all Started.
Internet Access
Host NAT
Windows NAT (WinNAT) on the host gives the lab subnet outbound access through the host’s own connection. Run these on the Hyper-V host after Install-Lab.
1. Check the host’s address on the lab switch. The switch takes the network definition’s name, and Hyper-V names the host’s adapter on it vEthernet (<switch name>). The NAT gateway is the host’s address on this adapter, inside the lab subnet.
$LabName = 'BasicLab'
Get-VMSwitch | Format-Table Name, SwitchType
Get-NetIPAddress -InterfaceAlias "vEthernet ($LabName)" -AddressFamily IPv4 | Format-Table IPAddress, PrefixLength
If 192.168.10.1 is not listed, add it:
New-NetIPAddress -InterfaceAlias "vEthernet ($LabName)" -IPAddress '192.168.10.1' -PrefixLength 24
2. Create the NAT. A host supports only one NAT network, so check for an existing one first and remove it if it belongs to an old lab.
Get-NetNat
New-NetNat -Name "$($LabName)NAT" -InternalIPInterfaceAddressPrefix '192.168.10.0/24'
3. Set the gateway on the VMs and DNS forwarders on the DC. WinNAT does not assign addresses, gateways or DNS to guests.
Import-Lab -Name $LabName
Invoke-LabCommand -ComputerName (Get-LabVM).Name -ScriptBlock {
$nic = Get-NetAdapter | Where-Object Status -eq 'Up' | Select-Object -First 1
Remove-NetRoute -DestinationPrefix '0.0.0.0/0' -Confirm:$false -ErrorAction SilentlyContinue
New-NetRoute -DestinationPrefix '0.0.0.0/0' -InterfaceIndex $nic.ifIndex -NextHop '192.168.10.1'
}
Invoke-LabCommand -ComputerName DC01 -ScriptBlock {
Add-DnsServerForwarder -IPAddress 1.1.1.1, 8.8.8.8 -ErrorAction SilentlyContinue
}
4. Test.
Invoke-LabCommand -ComputerName DC01 -ScriptBlock {
Test-NetConnection -ComputerName 8.8.8.8 -Port 443
Resolve-DnsName www.microsoft.com -Type A
} -PassThru
Expected: TcpTestSucceeded : True and A records returned.
Other Network Options
| Option | Internet | Definition |
|---|---|---|
| Internal only | None | Add-LabVirtualNetworkDefinition -Name $LabName -AddressSpace $AddressSpace (switch type defaults to Internal) |
| Internal plus host NAT | Outbound | Internal network, then Host NAT |
| External | Bridged to the physical LAN | Add -HyperVProperties @{ SwitchType = 'External'; AdapterName = '<HOST_ADAPTER>' } |
| Routing VM | Through the VM | A machine with the Routing role on both the lab network and an external network |
Routing VM example. AutomatedLab handles routing for a network that contains a machine with the Routing role:
Add-LabVirtualNetworkDefinition -Name 'External' -HyperVProperties @{ SwitchType = 'External'; AdapterName = '<HOST_ADAPTER>' }
$nics = @(
New-LabNetworkAdapterDefinition -VirtualSwitch $LabName -Ipv4Address '192.168.10.1'
New-LabNetworkAdapterDefinition -VirtualSwitch 'External' -UseDhcp
)
Add-LabMachineDefinition -Name Router01 -OperatingSystem $ServerOS -Roles Routing -NetworkAdapter $nics
Get-NetAdapter | Where-Object Status -eq 'Up' lists the host adapter names.
Working With the Lab
A new PowerShell session has no lab loaded. Run Import-Lab before any other lab command.
| Task | Command |
|---|---|
| Load the lab | Import-Lab -Name BasicLab |
| VM state | Get-LabVMStatus |
| Console (VMConnect) | Connect-LabVM -ComputerName DC01 |
| Remote session | Enter-LabPSSession -ComputerName DC01 |
| Run a command and see output | Invoke-LabCommand -ComputerName DC01 -ScriptBlock { hostname } -PassThru |
| Copy a file to a VM | Copy-LabFileItem -Path C:\Scripts\Test.ps1 -ComputerName DC01 -DestinationFolderPath C:\Scripts |
| Start or stop all VMs | Start-LabVM -All / Stop-LabVM -All |
| Checkpoint all VMs | Checkpoint-LabVM -All -SnapshotName 'Initial-Deploy' |
| Restore all VMs | Restore-LabVMSnapshot -All -SnapshotName 'Initial-Deploy' |
| List checkpoints | Get-LabVMSnapshot |
Hyper-V’s own file copy (Copy-VMFile) needs the Guest Service Interface integration service, the only one that is off by default on Windows guests:
Get-LabVM | ForEach-Object { Enable-VMIntegrationService -VMName $_.Name -Name 'Guest Service Interface' }
Copy-VMFile -VMName DC01 -SourcePath 'C:\Scripts\Test.ps1' -DestinationPath 'C:\Scripts\Test.ps1' -FileSource Host -CreateFullPath
Modifying the Lab
| Change | Edit |
|---|---|
| Lab name | $LabName (also names the network, switch and NAT) |
| Domain | $DomainName |
| Subnet | $AddressSpace and every -IpAddress; each address must be inside the subnet |
| Memory | -Memory on one machine, or the default in $PSDefaultParameterValues |
| Operating system | $ServerOS / $ClientOS, copied from Get-LabAvailableOperatingSystem |
| Add a VM | Another Add-LabMachineDefinition line before Install-Lab |
| Remove a deployed VM | Remove-LabVM -Name Srv02, then delete its line from the script |
Roles go in -Roles as a comma-separated list, for example -Roles CaRoot, FileServer. A machine can have none, one or several; some are mutually exclusive, such as RootDC and FirstChildDC. Common roles:
| Role | Purpose |
|---|---|
RootDC | First DC of a new forest |
FirstChildDC | First DC of a child domain |
DC | Additional domain controller |
CaRoot / CaSubordinate | Certification authority |
DHCP | DHCP server |
FileServer | File server |
WebServer | IIS |
Routing | Routing between lab networks |
SQLServer2019 / SQLServer2022 | SQL Server |
The full list is in the AutomatedLab roles documentation.
Removing the Lab
Import-Lab -Name BasicLab
Remove-Lab -Name BasicLab -Confirm:$false
Get-NetNat | Where-Object Name -eq 'BasicLabNAT' | Remove-NetNat -Confirm:$false
The NAT was created outside AutomatedLab, so it is removed separately. Afterwards, check the VmPath folder for anything left behind.
Troubleshooting
| Symptom | Cause | Fix |
|---|---|---|
| Operating system not found when the script runs | Name differs from the ISO, or a non-en-US ISO was skipped | Copy the exact name from Get-LabAvailableOperatingSystem; set DoNotSkipNonNonEnglishIso |
| IP address not in the network range | An -IpAddress falls outside $AddressSpace | Use host addresses inside the subnet |
Add-LabNatDefinition is not recognised | AutomatedLab has no such cmdlet | Use Host NAT |
New-NetNat fails or NAT behaves unpredictably | A NAT already exists; WinNAT supports one internal prefix per host | Get-NetNat, remove the old NAT, retry |
| VMs have no internet | No default route on the VMs, or no gateway address on the host adapter | Host NAT steps 1 and 3 |
| Lab commands return nothing in a new session | Lab not loaded | Import-Lab -Name BasicLab |
Invoke-LabCommand shows no output | Output is returned only with -PassThru | Add -PassThru |
Copy-VMFile fails | Guest Service Interface is off | Enable it (see Working With the Lab) |
Update-Module: “no valid module was found in the module directory” | Module not installed with Install-Module, or not in a module folder this PowerShell searches | Get-Module AutomatedLab -ListAvailable; update an MSI install with the newer MSI |
| Re-running the script after a failed deployment fails | Partial lab left behind | Remove-Lab, then re-run |
References
- AutomatedLab - Documentation (requirements and supported PowerShell versions): https://automatedlab.org/en/latest/
- AutomatedLab - Installation: https://automatedlab.org/en/latest/Wiki/Basic/install/
- AutomatedLab - Create a new lab: https://automatedlab.org/en/latest/Wiki/Basic/createnewlab/
- AutomatedLab - Networks and IP addresses: https://automatedlab.org/en/latest/Wiki/Basic/networksandaddresses/
- AutomatedLab - Roles: https://automatedlab.org/en/latest/Wiki/Roles/roles/
- AutomatedLab - Advanced configuration (settings): https://automatedlab.org/en/latest/Wiki/Advanced/automatedlabconfig/
- AutomatedLab - GitHub repository and releases: https://github.com/AutomatedLab/AutomatedLab
- AutomatedLab - PowerShell Gallery: https://www.powershellgallery.com/packages/AutomatedLab/
- AutomatedLabDefinition - Command help (no NAT cmdlet): https://powershellgallery.com/packages/AutomatedLabDefinition/5.55.0/Content/en-us/AutomatedLabDefinition-help.xml
- PSFramework - Configuration system: https://psframework.org/documentation/documents/psframework/configuration.html
- Microsoft - Enable Hyper-V on Windows: https://learn.microsoft.com/en-us/virtualization/hyper-v-on-windows/quick-start/enable-hyper-v
- Microsoft - Set up a NAT network: https://learn.microsoft.com/en-us/windows-server/virtualization/hyper-v/setup-nat-network
- Microsoft - Manage Hyper-V integration services: https://learn.microsoft.com/en-us/windows-server/virtualization/hyper-v/manage/manage-hyper-v-integration-services
- Microsoft - Update-Module: https://learn.microsoft.com/en-us/powershell/module/powershellget/update-module
- Microsoft - about_Parameters_Default_Values: https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_parameters_default_values
- Microsoft - New-NetRoute: https://learn.microsoft.com/en-us/powershell/module/nettcpip/new-netroute
- Microsoft - Add-DnsServerForwarder: https://learn.microsoft.com/en-us/powershell/module/dnsserver/add-dnsserverforwarder

