Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save jpbruckler/3361759ce79f2583f75a7b5d097e9e51 to your computer and use it in GitHub Desktop.
Save jpbruckler/3361759ce79f2583f75a7b5d097e9e51 to your computer and use it in GitHub Desktop.
Lab definition using AutomatedLab
<#
File below is used to deploy a Hyper-V based lab environment using AutomatedLab
(https://github.com/AutomatedLab/AutomatedLab)
Operating systems needed: Windows Server 2022 Datacenter Edition.
Download from wherever you get your server ISOs.
For the software installation section, you will need to download 7-zip and PowerShell
from official sources and place in the $labSources\SoftwarePackages folder.
Script below will install:
========================================================================
Networks
========================================================================
Network Name Address Space
------------ --------------
RoutingPlane 172.30.10.0/24
Domain 172.30.11.0/24
Server 172.30.12.0/24
Client 172.30.13.0/24
========================================================================
Virtual Machines
========================================================================
Machine Name Role Address Gateway
------------ ------------- ----------------- ---------------
lab-rtr-01 Routing and Remote Access 172.30.10.1
172.30.11.1
172.30.12.1
172.30.13.1
DHCP (External)
lab-dc-01 Domain Controller 172.30.11.10 172.30.11.1
lab-ca-01 Root CA 172.30.11.11 172.30.11.1
lab-ca-02 Subordinate CA 172.30.11.12 172.30.11.1
lab-svr-fs01 File Server 172.30.12.10 172.30.12.1
lab-svr-web01 Web Server 172.30.12.11 172.30.12.1
lab-srv-app01 None. General app svr DHCP
========================================================================
Software installation
========================================================================
For the software installation section, you will need to download 7-zip and PowerShell
from official sources and place in the $labSources\SoftwarePackages folder. Update the
file names to match the downloaded software versions.
Software Version
--------- --------
7-zip 7z2201
PowerShell 7.3.4
#>
$labName = 'dc-with-pki-multinet'
$AdminUser = 'Administrator'
$AdminPass = 'L4bP@ssw0rd'
$DomainName = 'lab.local'
New-LabDefinition -Name $labName -DefaultVirtualizationEngine HyperV
Set-LabInstallationCredential -Username $AdminUser -Password $AdminPass
Add-LabDomainDefinition -Name $DomainName -AdminUser $AdminUser -AdminPassword $AdminPass
$PSDefaultParameterValues = @{
'Add-LabMachineDefinition:ToolsPath'= "$labSources\Tools"
'Add-LabMachineDefinition:DomainName' = $DomainName
'Add-LabMachineDefinition:DnsServer1' = '172.30.11.10'
'Add-LabMachineDefinition:OperatingSystem' = 'Windows Server 2022 Datacenter (Desktop Experience)'
'Add-LabMachineDefinition:Memory' = 4gb
'Add-LabMachineDefinition:MinMemory' = 512mb
'Add-LabMachineDefinition:MaxMemory' = 6gb
}
Add-LabVirtualNetworkDefinition -Name RoutingPlane -AddressSpace 172.30.10.0/24
Add-LabVirtualNetworkDefinition -Name Domain -AddressSpace 172.30.11.0/24
Add-LabVirtualNetworkDefinition -Name Server -AddressSpace 172.30.12.0/24
Add-LabVirtualNetworkDefinition -Name Client -AddressSpace 172.30.13.0/24
Add-LabVirtualNetworkDefinition -Name 'Default Switch' -HyperVProperties @{ SwitchType = 'External'; AdapterName = 'Wi-Fi' }
#region Routing
$r1adap = @(
New-LabNetworkAdapterDefinition -InterfaceName Routing -VirtualSwitch RoutingPlane -Ipv4Address 172.30.10.1
New-LabNetworkAdapterDefinition -InterfaceName Domain -VirtualSwitch Domain -Ipv4Address 172.30.11.1
New-LabNetworkAdapterDefinition -InterfaceName Server -VirtualSwitch Server -Ipv4Address 172.30.12.1
New-LabNetworkAdapterDefinition -InterfaceName Client -VirtualSwitch Client -Ipv4Address 172.30.13.1
New-LabNetworkAdapterDefinition -interfaceName External -VirtualSwitch 'Default Switch' -UseDhcp
)
Add-LabMachineDefinition -Name lab-rtr-01 -Roles Routing -NetworkAdapter $r1adap -Memory 2GB
#endregion
#region Domain
Add-LabMachineDefinition -Name lab-dc-01 -Network Domain -IpAddress 172.30.11.10 -Gateway 172.30.11.1 -Roles RootDC
#endregion
#region CA
$role = Get-LabMachineRoleDefinition -Role CaRoot @{
CACommonName = 'labRootCA'
KeyLength = '4096'
ValidityPeriod = 'Years'
ValidityPeriodUnits = '20'
}
Add-LabMachineDefinition -name lab-ca-01 -Network Domain -IpAddress 172.30.11.11 -Gateway 172.30.11.1 -Roles $role
$role = Get-LabMachineRoleDefinition -Role CaSubordinate @{
CACommonName = 'labSubCA1'
KeyLength = '2048'
ValidityPeriod = 'Years'
ValidityPeriodUnits = '8' }
Add-LabMachineDefinition -name lab-ca-02 -Network Domain -IpAddress 172.30.11.12 -Gateway 172.30.11.1 -Roles $role
#endregion
#region member servers
Add-LabMachineDefinition -Name lab-srv-fs01 -Network Server -IpAddress 172.30.12.10 -Gateway 172.30.12.1 -Roles FileServer
Add-LabMachineDefinition -Name lab-srv-web01 -Network Server -IpAddress 172.30.12.11 -Gateway 172.30.12.1 -Roles WebServer
Add-LabDiskDefinition -Name appsrv_datadisk -DiskSizeInGb 100 -Label Apps -DriveLetter D -AllocationUnitSize 64kb
Add-LabMachineDefinition -Name lab-srv-app01 -Network Server -DiskName appsrv_datadisk
#endregion
Install-Lab -NetworkSwitches -BaseImages -VMs
Install-Lab -Domains
Install-Lab -Routing
Enable-LabInternalRouting -RoutingNetworkName RoutingPlane -Verbose
Install-Lab -CA
Enable-LabCertificateAutoenrollment -Computer -User -CodeSigning
Install-Lab -StartRemainingMachines
Enable-LabVMRemoting -All
# Install Software on all machines
$LabVMs = Get-LabVM | Select-Object -ExpandProperty Name | Where-Object { $_ -notlike 'rtr*' }
$LabVMs | ForEach-Object {
# Create log directory
Invoke-LabCommand -ComputerName $_ -ScriptBlock { New-Item -ItemType Directory -Path C:\lablogs -force }
# 7-zip
Install-LabSoftwarePackage -Path $labSources\SoftwarePackages\7z2201-x64.exe -CommandLine '/S' -ComputerName $_
# PowerShell 7
Install-LabSoftwarePackage -Path $labSources\SoftwarePackages\PowerShell-7.3.4-win-x64.msi -CommandLine '/qn /l*v C:\lablogs\PowerShell7.3.4.install.log' -ComputerName $_
}
Show-LabDeploymentSummary -Detailed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment