├── A02 ├── 01_Installation.ps1 ├── 02_First_CMDLET.ps1 └── 03_First_Lab.ps1 ├── A03 ├── 01_First_Network.ps1 ├── 02_Single_VM.ps1 ├── 03_Single_VM_Internet_Connection.ps1 ├── 04_Single_Domain_joined_Client.ps1 └── 05_Single_Domain_joined_Client_Internet_Connection.ps1 ├── A04 ├── 01_Deploy_DC.ps1 ├── 02_Deploy_CA.ps1 ├── 03_Deploy_WebServer.ps1 ├── 04_Deploy_CL01.ps1 ├── 05_Install_Software.ps1 ├── 06_Deploy_AD_Users.ps1 ├── 07_Deploy_complete_Lab.ps1 ├── 08_Sample_CMDLETs.ps1 └── 09_Deploy_Clients_RDP_File.ps1 ├── CustomLabRessources ├── CopyFiles │ ├── CreateADUsers.ps1 │ ├── DeployWebsite.ps1 │ ├── index.html │ ├── mapdc.ps1 │ └── users.csv └── Custom │ └── mapdc.ps1 ├── Links.md ├── README.md └── testResults.xml /A02/01_Installation.ps1: -------------------------------------------------------------------------------- 1 | #Hyper-V Installation on a Server 2 | Install-WindowsFeature -Name Hyper-V -ComputerName "computer_name" -IncludeManagementTools -Restart 3 | 4 | #Hyper-V Installation on a Windows 10/11 5 | Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V -All 6 | 7 | #MSI-Download: 8 | https://automatedlab.org/en/latest/Wiki/Basic/install/ 9 | 10 | #Install AutomatedLab with PowerShell 11 | Install-Module -Name AutomatedLab -AllowClobber -Force -Verbose 12 | 13 | #Set the LabSourcesFolder 14 | New-LabSourcesFolder -Drive H: 15 | 16 | #Get the SourcesFolder 17 | Get-LabSourcesLocation -------------------------------------------------------------------------------- /A02/02_First_CMDLET.ps1: -------------------------------------------------------------------------------- 1 | #Get the SourcesFolder 2 | Get-LabSourcesLocation 3 | 4 | #Check the ISO's and OS Versions's 5 | Get-LabAvailableOperatingSystem -Path H:\LabSources 6 | 7 | -------------------------------------------------------------------------------- /A02/03_First_Lab.ps1: -------------------------------------------------------------------------------- 1 | #Show available OS 2 | Get-LabAvailableOperatingSystem -Path H:\LabSources 3 | 4 | #New Lab Definition 5 | New-LabDefinition -Name MyFirstLab -DefaultVirtualizationEngine HyperV 6 | Add-LabMachineDefinition -Name Win10Demo -OperatingSystem 'Windows 10 Enterprise Evaluation' 7 | 8 | ##We didn't specify a password, the default is: Somepass1 9 | 10 | #Install Lab 11 | Install-Lab 12 | 13 | #Notification 14 | Send-ALNotification -Activity 'Installing Software' -Message 'Software being installed..' -Provider Toast,Ifttt 15 | 16 | #Install Software to TestLab-VM 17 | Install-LabSoftwarePackage -ComputerName Win10Demo -Path $labSources\SoftwarePackages\Notepad++.exe -CommandLine /S 18 | 19 | #Copy files to TestLab-VM 20 | Copy-LabFileItem -Path 'H:\LabSources\ToCopy' -ComputerName Win10Demo -DestinationFolderPath C:\Temp 21 | 22 | #Show Labs 23 | Get-Lab -List 24 | 25 | #Deployment Summary 26 | Show-LabDeploymentSummary -Detailed 27 | 28 | #Remove Lab 29 | Remove-Lab -Path C:\ProgramData\AutomatedLab\Labs\MyFirstLab -------------------------------------------------------------------------------- /A03/01_First_Network.ps1: -------------------------------------------------------------------------------- 1 | #General 2 | $LabName = "TestLab" 3 | 4 | #Network 5 | New-LabDefinition -Name $LabName -DefaultVirtualizationEngine HyperV 6 | Add-LabVirtualNetworkDefinition -Name $LabName -AddressSpace 192.168.123.0/24 7 | 8 | #Install Lab 9 | Install-Lab 10 | 11 | #Deployment Summary 12 | Show-LabDeploymentSummary -Detailed 13 | 14 | #List all Labs 15 | Get-Lab -List 16 | 17 | #Remove the Lab 18 | Remove-Lab -Path C:\ProgramData\AutomatedLab\Labs\TestLab -------------------------------------------------------------------------------- /A03/02_Single_VM.ps1: -------------------------------------------------------------------------------- 1 | #Show available OS 2 | Get-LabAvailableOperatingSystem -Path H:\LabSources 3 | 4 | #New Lab Definition 5 | New-LabDefinition -Name Win10 -DefaultVirtualizationEngine HyperV 6 | 7 | #Lab Machine Definition 8 | Add-LabMachineDefinition -Name Client1 -Memory 4GB -OperatingSystem 'Windows 10 Enterprise Evaluation' 9 | 10 | #Install Lab 11 | Install-Lab 12 | 13 | #We didn't specify a password, the default is: Somepass1 14 | 15 | #Deployment Summary 16 | Show-LabDeploymentSummary -Detailed 17 | 18 | #Remove Lab 19 | Remove-Lab -Path C:\ProgramData\AutomatedLab\Labs\Win10 -------------------------------------------------------------------------------- /A03/03_Single_VM_Internet_Connection.ps1: -------------------------------------------------------------------------------- 1 | #Show available OS 2 | Get-LabAvailableOperatingSystem -Path H:\LabSources 3 | 4 | #New Lab Definition 5 | New-LabDefinition -Name Win10 -DefaultVirtualizationEngine HyperV 6 | 7 | #Virtual Switch 8 | Add-LabVirtualNetworkDefinition -Name 'Default Switch' -HyperVProperties @{ SwitchType = 'External'; AdapterName = 'vEthernet (Default Switch)' } 9 | 10 | #Lab VM Adapter settings 11 | $netAdapter = @() 12 | $netAdapter += New-LabNetworkAdapterDefinition -VirtualSwitch 'Default Switch' -UseDhcp 13 | 14 | #Lab Machine Definition 15 | Add-LabMachineDefinition -Name Client1 -Memory 4GB -OperatingSystem 'Windows 10 Enterprise Evaluation' -NetworkAdapter $netAdapter 16 | 17 | #Install Lab 18 | Install-Lab 19 | 20 | #We didn't specify a password, the default is: Somepass1 21 | 22 | #Deployment Summary 23 | Show-LabDeploymentSummary -Detailed 24 | 25 | #Remove Lab 26 | Remove-Lab -Path C:\ProgramData\AutomatedLab\Labs\Win10 -------------------------------------------------------------------------------- /A03/04_Single_Domain_joined_Client.ps1: -------------------------------------------------------------------------------- 1 | #Show available OS 2 | Get-LabAvailableOperatingSystem -Path G:\LabSources 3 | 4 | #New Lab Definition 5 | New-LabDefinition -Name Lab1 -DefaultVirtualizationEngine HyperV 6 | 7 | #Lab Machine Definition 8 | Add-LabMachineDefinition -Name DC1 -Memory 4GB -OperatingSystem 'Windows Server 2022 Datacenter Evaluation (Desktop Experience)' -Roles RootDC -DomainName tech.pri 9 | Add-LabMachineDefinition -Name Client1 -Memory 4GB -OperatingSystem 'Windows 10 Enterprise Evaluation' -DomainName tech.pri 10 | 11 | #Install Lab 12 | Install-Lab 13 | 14 | #Deployment Summary 15 | Show-LabDeploymentSummary -Detailed 16 | 17 | #Remove Lab 18 | Remove-Lab -Path C:\ProgramData\AutomatedLab\Labs\Lab1 -------------------------------------------------------------------------------- /A03/05_Single_Domain_joined_Client_Internet_Connection.ps1: -------------------------------------------------------------------------------- 1 | #Show available OS 2 | Get-LabAvailableOperatingSystem -Path H:\LabSources 3 | 4 | #New Lab Definition 5 | New-LabDefinition -Name Lab0 -DefaultVirtualizationEngine HyperV 6 | 7 | #Virtual Switch 8 | Add-LabVirtualNetworkDefinition -Name Lab0 9 | Add-LabVirtualNetworkDefinition -Name 'Default Switch' -HyperVProperties @{ SwitchType = 'External'; AdapterName = 'vEthernet (Default Switch)' } 10 | 11 | #Lab Machine Definition 12 | Add-LabMachineDefinition -Name DC1 -Memory 4GB -OperatingSystem 'Windows Server 2022 Datacenter Evaluation (Desktop Experience)' -Roles RootDC -Network Lab0 -DomainName tech.pri 13 | 14 | #Lab VM Adapter settings 15 | $netAdapter = @() 16 | $netAdapter += New-LabNetworkAdapterDefinition -VirtualSwitch Lab0 17 | $netAdapter += New-LabNetworkAdapterDefinition -VirtualSwitch 'Default Switch' -UseDhcp 18 | 19 | #Lab Machine Definition 20 | Add-LabMachineDefinition -Name Router1 -Memory 4GB -OperatingSystem 'Windows Server 2022 Datacenter Evaluation (Desktop Experience)' -Roles Routing -NetworkAdapter $netAdapter -DomainName tech.pri 21 | Add-LabMachineDefinition -Name Client1 -Memory 4GB -Network Lab0 -OperatingSystem 'Windows 10 Enterprise Evaluation' -DomainName tech.pri 22 | 23 | #Install Lab 24 | Install-Lab 25 | 26 | #We didn't specify a password, the default is: Somepass1 27 | 28 | #Deployment Summary 29 | Show-LabDeploymentSummary -Detailed 30 | 31 | #Remove Lab 32 | Remove-Lab -Path C:\ProgramData\AutomatedLab\Labs\Lab0 -------------------------------------------------------------------------------- /A04/01_Deploy_DC.ps1: -------------------------------------------------------------------------------- 1 | #General 2 | $LabName = "TechLab" 3 | $domain = 'tech.pri' 4 | $adminAcc = 'Administrator' 5 | $adminPass = 'P@ssw0rd' 6 | 7 | #New Lab Definition 8 | New-LabDefinition -Name $LabName -DefaultVirtualizationEngine HyperV 9 | 10 | #Virtual Switch 11 | Add-LabVirtualNetworkDefinition -Name $LabName -AddressSpace 192.168.123.0/24 12 | 13 | #Domain definition with the domain admin account 14 | Add-LabDomainDefinition -Name $domain -AdminUser $adminAcc -AdminPassword $adminPass 15 | Set-LabInstallationCredential -Username $adminAcc -Password $adminPass 16 | 17 | #Basic Parameters 18 | $PSDefaultParameterValues = @{ 19 | 'Add-LabMachineDefinition:Network' = $LabName 20 | 'Add-LabMachineDefinition:ToolsPath'= "$labSources\Tools" 21 | 'Add-LabMachineDefinition:IsDomainJoined'= $true 22 | 'Add-LabMachineDefinition:DomainName'= $domain 23 | 'Add-LabMachineDefinition:EnableWindowsFirewall'= $false 24 | 'Add-LabMachineDefinition:OperatingSystem'= 'Windows Server 2022 Datacenter Evaluation (Desktop Experience)' 25 | 'Add-LabMachineDefinition:Memory'= 4GB 26 | 'Add-LabMachineDefinition:MinMemory'= 2GB 27 | 'Add-LabMachineDefinition:MaxMemory'= 4GB 28 | 'Add-LabMachineDefinition:Processors'= 1 29 | } 30 | 31 | #Lab Machine Definition 32 | Add-LabMachineDefinition -Name "DC01" -IpAddress 192.168.123.1 -DomainName $domain -Roles RootDC 33 | 34 | #Install Lab 35 | Install-Lab 36 | 37 | #Deployment Summary 38 | Show-LabDeploymentSummary -Detailed 39 | 40 | #Show Labs 41 | Get-Lab -List 42 | 43 | #Remove Lab 44 | Remove-Lab -Path C:\ProgramData\AutomatedLab\Labs\TechLab -------------------------------------------------------------------------------- /A04/02_Deploy_CA.ps1: -------------------------------------------------------------------------------- 1 | #General 2 | $LabName = "TechLab" 3 | $domain = 'tech.pri' 4 | $adminAcc = 'Administrator' 5 | $adminPass = 'P@ssw0rd' 6 | 7 | #New Lab Definition 8 | New-LabDefinition -Name $LabName -DefaultVirtualizationEngine HyperV 9 | 10 | #Virtual Switch 11 | Add-LabVirtualNetworkDefinition -Name $LabName -AddressSpace 192.168.123.0/24 12 | 13 | #Domain definition with the domain admin account 14 | Add-LabDomainDefinition -Name $domain -AdminUser $adminAcc -AdminPassword $adminPass 15 | Set-LabInstallationCredential -Username $adminAcc -Password $adminPass 16 | 17 | #Basic Parameters 18 | $PSDefaultParameterValues = @{ 19 | 'Add-LabMachineDefinition:Network' = $LabName 20 | 'Add-LabMachineDefinition:ToolsPath'= "$labSources\Tools" 21 | 'Add-LabMachineDefinition:IsDomainJoined'= $true 22 | 'Add-LabMachineDefinition:DomainName'= $domain 23 | 'Add-LabMachineDefinition:EnableWindowsFirewall'= $false 24 | 'Add-LabMachineDefinition:OperatingSystem'= 'Windows Server 2022 Datacenter Evaluation (Desktop Experience)' 25 | 'Add-LabMachineDefinition:Memory'= 4GB 26 | 'Add-LabMachineDefinition:MinMemory'= 2GB 27 | 'Add-LabMachineDefinition:MaxMemory'= 4GB 28 | 'Add-LabMachineDefinition:Processors'= 1 29 | } 30 | 31 | #Lab Machine Definition 32 | Add-LabMachineDefinition -Name "DC01" -IpAddress 192.168.123.1 -DomainName $domain -Roles RootDC 33 | 34 | #CA Role Definition 35 | $role = Get-LabMachineRoleDefinition -Role CaRoot @{ 36 | CACommonName = "MyLabRootCA1" 37 | KeyLength = "2048" 38 | ValidityPeriod = "Weeks" 39 | ValidityPeriodUnits = "4" 40 | } 41 | 42 | #Lab Machine Definition 43 | Add-LabMachineDefinition -Name "CA01" -IpAddress 192.168.123.12 -Roles $role 44 | 45 | #Install Lab 46 | Install-Lab 47 | 48 | #Deployment Summary 49 | Show-LabDeploymentSummary -Detailed 50 | 51 | #Show Labs 52 | Get-Lab -List 53 | 54 | #Remove Lab 55 | Remove-Lab -Path C:\ProgramData\AutomatedLab\Labs\TechLab -------------------------------------------------------------------------------- /A04/03_Deploy_WebServer.ps1: -------------------------------------------------------------------------------- 1 | #General 2 | $LabName = "TechLab" 3 | $domain = 'tech.pri' 4 | $adminAcc = 'Administrator' 5 | $adminPass = 'P@ssw0rd' 6 | 7 | #New Lab Definition 8 | New-LabDefinition -Name $LabName -DefaultVirtualizationEngine HyperV 9 | 10 | #Virtual Switch 11 | Add-LabVirtualNetworkDefinition -Name $LabName -AddressSpace 192.168.123.0/24 12 | 13 | #Domain definition with the domain admin account 14 | Add-LabDomainDefinition -Name $domain -AdminUser $adminAcc -AdminPassword $adminPass 15 | Set-LabInstallationCredential -Username $adminAcc -Password $adminPass 16 | 17 | #Basic Parameters 18 | $PSDefaultParameterValues = @{ 19 | 'Add-LabMachineDefinition:Network' = $LabName 20 | 'Add-LabMachineDefinition:ToolsPath'= "$labSources\Tools" 21 | 'Add-LabMachineDefinition:IsDomainJoined'= $true 22 | 'Add-LabMachineDefinition:DomainName'= $domain 23 | 'Add-LabMachineDefinition:EnableWindowsFirewall'= $false 24 | 'Add-LabMachineDefinition:OperatingSystem'= 'Windows Server 2022 Datacenter Evaluation (Desktop Experience)' 25 | 'Add-LabMachineDefinition:Memory'= 4GB 26 | 'Add-LabMachineDefinition:MinMemory'= 2GB 27 | 'Add-LabMachineDefinition:MaxMemory'= 4GB 28 | 'Add-LabMachineDefinition:Processors'= 1 29 | } 30 | 31 | #Lab Machine Definition 32 | Add-LabMachineDefinition -Name "DC01" -IpAddress 192.168.123.1 -DomainName $domain -Roles RootDC -SkipDeployment 33 | 34 | #CA Role Definition 35 | $role = Get-LabMachineRoleDefinition -Role CaRoot @{ 36 | CACommonName = "MyLabRootCA1" 37 | KeyLength = "2048" 38 | ValidityPeriod = "Weeks" 39 | ValidityPeriodUnits = "4" 40 | } 41 | 42 | #Lab Machine Definition 43 | Add-LabMachineDefinition -Name "CA01" -IpAddress 192.168.123.12 -Roles $role -SkipDeployment 44 | 45 | #Lab Machine Definition 46 | Add-LabMachineDefinition -Name "WS01" -IpAddress 192.168.123.13 -Roles WebServer 47 | 48 | #Install Lab 49 | Install-Lab 50 | 51 | #Copy Files 52 | Copy-LabFileItem -Path 'H:\LabSources\CopyFiles' -ComputerName "WS01" -DestinationFolderPath C:\ 53 | 54 | #Run Scripts 55 | Invoke-LabCommand -ComputerName "WS01" -ScriptBlock {Invoke-Expression "&'C:\CopyFiles\DeployWebsite.ps1'"} 56 | 57 | #Deployment Summary 58 | Show-LabDeploymentSummary -Detailed 59 | 60 | #Show Labs 61 | Get-Lab -List 62 | 63 | #Remove Lab 64 | Remove-Lab -Path C:\ProgramData\AutomatedLab\Labs\TechLab -------------------------------------------------------------------------------- /A04/04_Deploy_CL01.ps1: -------------------------------------------------------------------------------- 1 | #General 2 | $LabName = "TechLab" 3 | $domain = 'tech.pri' 4 | $adminAcc = 'Administrator' 5 | $adminPass = 'P@ssw0rd' 6 | 7 | #New Lab Definition 8 | New-LabDefinition -Name $LabName -DefaultVirtualizationEngine HyperV 9 | 10 | #Virtual Switch 11 | Add-LabVirtualNetworkDefinition -Name $LabName -AddressSpace 192.168.123.0/24 12 | 13 | #Domain definition with the domain admin account 14 | Add-LabDomainDefinition -Name $domain -AdminUser $adminAcc -AdminPassword $adminPass 15 | Set-LabInstallationCredential -Username $adminAcc -Password $adminPass 16 | 17 | #Basic Parameters 18 | $PSDefaultParameterValues = @{ 19 | 'Add-LabMachineDefinition:Network' = $LabName 20 | 'Add-LabMachineDefinition:ToolsPath'= "$labSources\Tools" 21 | 'Add-LabMachineDefinition:IsDomainJoined'= $true 22 | 'Add-LabMachineDefinition:DomainName'= $domain 23 | 'Add-LabMachineDefinition:EnableWindowsFirewall'= $false 24 | 'Add-LabMachineDefinition:OperatingSystem'= 'Windows Server 2022 Datacenter Evaluation (Desktop Experience)' 25 | 'Add-LabMachineDefinition:Memory'= 4GB 26 | 'Add-LabMachineDefinition:MinMemory'= 2GB 27 | 'Add-LabMachineDefinition:MaxMemory'= 4GB 28 | 'Add-LabMachineDefinition:Processors'= 1 29 | } 30 | 31 | #Lab Machine Definition 32 | Add-LabMachineDefinition -Name "DC01" -IpAddress 192.168.123.1 -DomainName $domain -Roles RootDC -SkipDeployment 33 | 34 | #CA Role Definition 35 | $role = Get-LabMachineRoleDefinition -Role CaRoot @{ 36 | CACommonName = "MyLabRootCA1" 37 | KeyLength = "2048" 38 | ValidityPeriod = "Weeks" 39 | ValidityPeriodUnits = "4" 40 | } 41 | 42 | #Lab Machine Definition 43 | Add-LabMachineDefinition -Name "CA01" -IpAddress 192.168.123.12 -Roles $role -SkipDeployment 44 | 45 | #Lab Machine Definition 46 | Add-LabMachineDefinition -Name "WS01" -IpAddress 192.168.123.13 -Roles WebServer -SkipDeployment 47 | 48 | #Lab Machine Definition 49 | $postInstallActivity = Get-LabPostInstallationActivity -ScriptFileName mapdc.ps1 -DependencyFolder $labSources\PostInstallationActivities\Custom 50 | Add-LabMachineDefinition -Name "CL01" -IpAddress 192.168.123.100 -Memory 2GB -OperatingSystem 'Windows 10 Enterprise Evaluation' -PostInstallationActivity $postInstallActivity 51 | 52 | #Install Lab 53 | Install-Lab 54 | 55 | #Deployment Summary 56 | Show-LabDeploymentSummary -Detailed 57 | 58 | #Show Labs 59 | Get-Lab -List 60 | 61 | #Remove Lab 62 | Remove-Lab -Path C:\ProgramData\AutomatedLab\Labs\TechLab -------------------------------------------------------------------------------- /A04/05_Install_Software.ps1: -------------------------------------------------------------------------------- 1 | #General 2 | $LabName = "TechLab" 3 | $domain = 'tech.pri' 4 | $adminAcc = 'Administrator' 5 | $adminPass = 'P@ssw0rd' 6 | 7 | #New Lab Definition 8 | New-LabDefinition -Name $LabName -DefaultVirtualizationEngine HyperV 9 | 10 | #Virtual Switch 11 | Add-LabVirtualNetworkDefinition -Name $LabName -AddressSpace 192.168.123.0/24 12 | 13 | #Domain definition with the domain admin account 14 | Add-LabDomainDefinition -Name $domain -AdminUser $adminAcc -AdminPassword $adminPass 15 | Set-LabInstallationCredential -Username $adminAcc -Password $adminPass 16 | 17 | #Basic Parameters 18 | $PSDefaultParameterValues = @{ 19 | 'Add-LabMachineDefinition:Network' = $LabName 20 | 'Add-LabMachineDefinition:ToolsPath'= "$labSources\Tools" 21 | 'Add-LabMachineDefinition:IsDomainJoined'= $true 22 | 'Add-LabMachineDefinition:DomainName'= $domain 23 | 'Add-LabMachineDefinition:EnableWindowsFirewall'= $false 24 | 'Add-LabMachineDefinition:OperatingSystem'= 'Windows Server 2022 Datacenter Evaluation (Desktop Experience)' 25 | 'Add-LabMachineDefinition:Memory'= 4GB 26 | 'Add-LabMachineDefinition:MinMemory'= 2GB 27 | 'Add-LabMachineDefinition:MaxMemory'= 4GB 28 | 'Add-LabMachineDefinition:Processors'= 1 29 | } 30 | 31 | #Lab Machine Definition 32 | Add-LabMachineDefinition -Name "DC01" -IpAddress 192.168.123.1 -DomainName $domain -Roles RootDC 33 | 34 | #CA Role Definition 35 | $role = Get-LabMachineRoleDefinition -Role CaRoot @{ 36 | CACommonName = "MyLabRootCA1" 37 | KeyLength = "2048" 38 | ValidityPeriod = "Weeks" 39 | ValidityPeriodUnits = "4" 40 | } 41 | 42 | #Lab Machine Definition 43 | Add-LabMachineDefinition -Name "CA01" -IpAddress 192.168.123.12 -Roles $role 44 | 45 | #Lab Machine Definition 46 | Add-LabMachineDefinition -Name "WS01" -IpAddress 192.168.123.13 -Roles WebServer 47 | 48 | #Lab Machine Definition 49 | $postInstallActivity = Get-LabPostInstallationActivity -ScriptFileName mapdc.ps1 -DependencyFolder $labSources\PostInstallationActivities\Custom 50 | Add-LabMachineDefinition -Name "CL01" -IpAddress 192.168.123.100 -Memory 2GB -OperatingSystem 'Windows 10 Enterprise Evaluation' -PostInstallationActivity $postInstallActivity 51 | 52 | #Install Lab 53 | Install-Lab 54 | 55 | #Install software to all lab machines 56 | $apps = @() 57 | foreach ($installer in (Get-ChildItem $labSources\SoftwarePackages)){ 58 | $installerpath = "$labSources\SoftwarePackages\" + $installer.Name 59 | $apps += Get-LabSoftwarePackage -Path $installerpath -CommandLine /S 60 | } 61 | Install-LabSoftwarePackages -Machine (Get-LabVM -All) -SoftwarePackage $apps 62 | 63 | #Deployment Summary 64 | Show-LabDeploymentSummary -Detailed 65 | 66 | #Show Labs 67 | Get-Lab -List 68 | 69 | #Remove Lab 70 | Remove-Lab -Path C:\ProgramData\AutomatedLab\Labs\TechLab -------------------------------------------------------------------------------- /A04/06_Deploy_AD_Users.ps1: -------------------------------------------------------------------------------- 1 | #General 2 | $LabName = "TechLab" 3 | $domain = 'tech.pri' 4 | $adminAcc = 'Administrator' 5 | $adminPass = 'P@ssw0rd' 6 | 7 | #New Lab Definition 8 | New-LabDefinition -Name $LabName -DefaultVirtualizationEngine HyperV 9 | 10 | #Virtual Switch 11 | Add-LabVirtualNetworkDefinition -Name $LabName -AddressSpace 192.168.123.0/24 12 | 13 | #Domain definition with the domain admin account 14 | Add-LabDomainDefinition -Name $domain -AdminUser $adminAcc -AdminPassword $adminPass 15 | Set-LabInstallationCredential -Username $adminAcc -Password $adminPass 16 | 17 | #Basic Parameters 18 | $PSDefaultParameterValues = @{ 19 | 'Add-LabMachineDefinition:Network' = $LabName 20 | 'Add-LabMachineDefinition:ToolsPath'= "$labSources\Tools" 21 | 'Add-LabMachineDefinition:IsDomainJoined'= $true 22 | 'Add-LabMachineDefinition:DomainName'= $domain 23 | 'Add-LabMachineDefinition:EnableWindowsFirewall'= $false 24 | 'Add-LabMachineDefinition:OperatingSystem'= 'Windows Server 2022 Datacenter Evaluation (Desktop Experience)' 25 | 'Add-LabMachineDefinition:Memory'= 4GB 26 | 'Add-LabMachineDefinition:MinMemory'= 2GB 27 | 'Add-LabMachineDefinition:MaxMemory'= 4GB 28 | 'Add-LabMachineDefinition:Processors'= 1 29 | } 30 | 31 | #Lab Machine Definition 32 | Add-LabMachineDefinition -Name "DC01" -IpAddress 192.168.123.1 -DomainName $domain -Roles RootDC 33 | 34 | #CA Role Definition 35 | $role = Get-LabMachineRoleDefinition -Role CaRoot @{ 36 | CACommonName = "MyLabRootCA1" 37 | KeyLength = "2048" 38 | ValidityPeriod = "Weeks" 39 | ValidityPeriodUnits = "4" 40 | } 41 | 42 | #Lab Machine Definition 43 | Add-LabMachineDefinition -Name "CA01" -IpAddress 192.168.123.12 -Roles $role 44 | 45 | #Lab Machine Definition 46 | Add-LabMachineDefinition -Name "WS01" -IpAddress 192.168.123.13 -Roles WebServer 47 | 48 | #Lab Machine Definition 49 | $postInstallActivity = Get-LabPostInstallationActivity -ScriptFileName mapdc.ps1 -DependencyFolder $labSources\PostInstallationActivities\Custom 50 | Add-LabMachineDefinition -Name "CL01" -IpAddress 192.168.123.100 -Memory 2GB -OperatingSystem 'Windows 10 Enterprise Evaluation' -PostInstallationActivity $postInstallActivity 51 | 52 | #Install Lab 53 | Install-Lab 54 | 55 | #Install software to all lab machines 56 | $apps = @() 57 | foreach ($installer in (Get-ChildItem $labSources\SoftwarePackages)){ 58 | $installerpath = "$labSources\SoftwarePackages\" + $installer.Name 59 | $apps += Get-LabSoftwarePackage -Path $installerpath -CommandLine /S 60 | } 61 | Install-LabSoftwarePackages -Machine (Get-LabVM -All) -SoftwarePackage $apps 62 | 63 | #Copy Files 64 | Copy-LabFileItem -Path 'H:\LabSources\CopyFiles' -ComputerName "DC01" -DestinationFolderPath C:\ 65 | 66 | #Run Scripts 67 | Invoke-LabCommand -ComputerName "DC01" -ScriptBlock {Invoke-Expression "&'C:\CopyFiles\CreateADUsers.ps1'"} 68 | 69 | #Deployment Summary 70 | Show-LabDeploymentSummary -Detailed 71 | 72 | #Show Labs 73 | Get-Lab -List 74 | 75 | #Remove Lab 76 | Remove-Lab -Path C:\ProgramData\AutomatedLab\Labs\TechLab -------------------------------------------------------------------------------- /A04/07_Deploy_complete_Lab.ps1: -------------------------------------------------------------------------------- 1 | #General 2 | $LabName = "TechLab" 3 | $domain = 'tech.pri' 4 | $adminAcc = 'Administrator' 5 | $adminPass = 'P@ssw0rd' 6 | 7 | #New Lab Definition 8 | New-LabDefinition -Name $LabName -DefaultVirtualizationEngine HyperV 9 | 10 | #Virtual Switch 11 | Add-LabVirtualNetworkDefinition -Name $LabName -AddressSpace 192.168.123.0/24 12 | 13 | #Domain definition with the domain admin account 14 | Add-LabDomainDefinition -Name $domain -AdminUser $adminAcc -AdminPassword $adminPass 15 | Set-LabInstallationCredential -Username $adminAcc -Password $adminPass 16 | 17 | #Basic Parameters 18 | $PSDefaultParameterValues = @{ 19 | 'Add-LabMachineDefinition:Network' = $LabName 20 | 'Add-LabMachineDefinition:ToolsPath'= "$labSources\Tools" 21 | 'Add-LabMachineDefinition:IsDomainJoined'= $true 22 | 'Add-LabMachineDefinition:DomainName'= $domain 23 | 'Add-LabMachineDefinition:EnableWindowsFirewall'= $false 24 | 'Add-LabMachineDefinition:OperatingSystem'= 'Windows Server 2022 Datacenter Evaluation (Desktop Experience)' 25 | 'Add-LabMachineDefinition:Memory'= 4GB 26 | 'Add-LabMachineDefinition:MinMemory'= 2GB 27 | 'Add-LabMachineDefinition:MaxMemory'= 4GB 28 | 'Add-LabMachineDefinition:Processors'= 1 29 | } 30 | 31 | #Lab Machine Definition 32 | Add-LabMachineDefinition -Name "DC01" -IpAddress 192.168.123.1 -DomainName $domain -Roles RootDC 33 | 34 | #CA Role Definition 35 | $role = Get-LabMachineRoleDefinition -Role CaRoot @{ 36 | CACommonName = "MyLabRootCA1" 37 | KeyLength = "2048" 38 | ValidityPeriod = "Weeks" 39 | ValidityPeriodUnits = "4" 40 | } 41 | 42 | #Lab Machine Definition 43 | Add-LabMachineDefinition -Name "CA01" -IpAddress 192.168.123.12 -Roles $role 44 | 45 | #Lab Machine Definition 46 | Add-LabMachineDefinition -Name "WS01" -IpAddress 192.168.123.13 -Roles WebServer 47 | 48 | #Lab Machine Definition 49 | $postInstallActivity = Get-LabPostInstallationActivity -ScriptFileName mapdc.ps1 -DependencyFolder $labSources\PostInstallationActivities\Custom 50 | Add-LabMachineDefinition -Name "CL01" -IpAddress 192.168.123.100 -Memory 2GB -OperatingSystem 'Windows 10 Enterprise Evaluation' -PostInstallationActivity $postInstallActivity 51 | 52 | #Install Lab 53 | Install-Lab 54 | 55 | #Install software to all lab machines 56 | $apps = @() 57 | foreach ($installer in (Get-ChildItem $labSources\SoftwarePackages)){ 58 | $installerpath = "$labSources\SoftwarePackages\" + $installer.Name 59 | $apps += Get-LabSoftwarePackage -Path $installerpath -CommandLine /S 60 | } 61 | Install-LabSoftwarePackages -Machine (Get-LabVM -All) -SoftwarePackage $apps 62 | 63 | #Copy Files 64 | Copy-LabFileItem -Path 'H:\LabSources\CopyFiles' -ComputerName "DC01" -DestinationFolderPath C:\ 65 | Copy-LabFileItem -Path 'H:\LabSources\CopyFiles' -ComputerName "WS01" -DestinationFolderPath C:\ 66 | 67 | #Run Scripts 68 | Invoke-LabCommand -ComputerName "DC01" -ScriptBlock {Invoke-Expression "&'C:\CopyFiles\CreateADUsers.ps1'"} 69 | Invoke-LabCommand -ComputerName "WS01" -ScriptBlock {Invoke-Expression "&'C:\CopyFiles\DeployWebsite.ps1'"} 70 | 71 | #Deployment Summary 72 | Show-LabDeploymentSummary -Detailed 73 | 74 | #Show Labs 75 | Get-Lab -List 76 | 77 | #Remove Lab 78 | Remove-Lab -Path C:\ProgramData\AutomatedLab\Labs\TechLab -------------------------------------------------------------------------------- /A04/08_Sample_CMDLETs.ps1: -------------------------------------------------------------------------------- 1 | #List all Labs 2 | Get-Lab -List 3 | 4 | #List Infos from a Lab 5 | Get-Lab 6 | 7 | #Import Lab - after restart or in other PS session: 8 | Import-Lab TechLab 9 | 10 | #Status 11 | #https://automatedlab.org/en/latest/AutomatedLab/en-us/Get-LabVMStatus/ 12 | Get-LabVMStatus -ComputerName DC01 13 | 14 | #Enable Remoting 15 | #https://automatedlab.org/en/latest/AutomatedLab/en-us/Enable-LabVMRemoting/ 16 | Enable-LabVMRemoting -ComputerName DC01 #If necessary 17 | Enter-LabPSSession -ComputerName DC01 18 | 19 | 20 | #Remove VM 21 | #https://automatedlab.org/en/latest/AutomatedLab/en-us/Remove-LabVM/ 22 | Remove-LabVM -Name WS01 23 | 24 | #Snapshot 25 | #https://automatedlab.org/en/latest/AutomatedLab/en-us/Get-LabVMSnapshot/ 26 | Get-LabVMSnapshot -ComputerName CL01 27 | Checkpoint-LabVM -ComputerName CL01 -SnapshotName "CL01 - (07/25/2021)" 28 | Restore-LabVMSnapshot -ComputerName CL01 -SnapshotName "CL01 - (07/25/2021)" 29 | Remove-LabVMSnapshot -ComputerName CL01 30 | 31 | #Get RDP Files 32 | #https://automatedlab.org/en/latest/AutomatedLab/en-us/Get-LabVMRdpFile/ 33 | Get-LabVMRdpFile -UseLocalCredential -All -Path $labSources 34 | 35 | #Get UpTime 36 | #https://automatedlab.org/en/latest/AutomatedLab/en-us/Get-LabVMUptime/ 37 | Get-LabVMUptime -ComputerName DC01 38 | 39 | #Install Windows Feature 40 | #https://automatedlab.org/en/latest/AutomatedLab/en-us/Get-LabWindowsFeature/ 41 | Install-LabWindowsFeature -ComputerName WS01 -FeatureName RSAT -IncludeAllSubFeature 42 | Get-LabWindowsFeature WS01 -FeatureName RSAT 43 | 44 | #Start VM 45 | #https://automatedlab.org/en/latest/AutomatedLab/en-us/Start-LabVM/ 46 | Start-LabVM DC01 47 | 48 | #Stop VM 49 | #https://automatedlab.org/en/latest/AutomatedLab/en-us/Stop-LabVM/ 50 | Stop-LabVM DC01 51 | 52 | #Invoke-LabCommand 53 | #https://automatedlab.org/en/latest/Wiki/Basic/invokelabcommand/ 54 | Invoke-LabCommand -ScriptBlock { Get-Date } -ComputerName (Get-LabVM) -PassThru -------------------------------------------------------------------------------- /A04/09_Deploy_Clients_RDP_File.ps1: -------------------------------------------------------------------------------- 1 | #General 2 | $LabName = "TechLab" 3 | $domain = 'tech.pri' 4 | $adminAcc = 'Administrator' 5 | $adminPass = 'P@ssw0rd' 6 | 7 | #New Lab Definition 8 | New-LabDefinition -Name $LabName -DefaultVirtualizationEngine HyperV 9 | 10 | #Virtual Switch 11 | Add-LabVirtualNetworkDefinition -Name $LabName -AddressSpace 192.168.123.0/24 12 | 13 | #Domain definition with the domain admin account 14 | Add-LabDomainDefinition -Name $domain -AdminUser $adminAcc -AdminPassword $adminPass 15 | Set-LabInstallationCredential -Username $adminAcc -Password $adminPass 16 | 17 | #Basic Parameters 18 | $PSDefaultParameterValues = @{ 19 | 'Add-LabMachineDefinition:Network' = $LabName 20 | 'Add-LabMachineDefinition:ToolsPath'= "$labSources\Tools" 21 | 'Add-LabMachineDefinition:IsDomainJoined'= $true 22 | 'Add-LabMachineDefinition:DomainName'= $domain 23 | 'Add-LabMachineDefinition:EnableWindowsFirewall'= $false 24 | 'Add-LabMachineDefinition:OperatingSystem'= 'Windows Server 2022 Datacenter Evaluation (Desktop Experience)' 25 | 'Add-LabMachineDefinition:Memory'= 4GB 26 | 'Add-LabMachineDefinition:MinMemory'= 2GB 27 | 'Add-LabMachineDefinition:MaxMemory'= 4GB 28 | 'Add-LabMachineDefinition:Processors'= 1 29 | } 30 | 31 | #Lab Machine Definition 32 | Add-LabMachineDefinition -Name "DC01" -IpAddress 192.168.123.1 -DomainName $domain -Roles RootDC 33 | 34 | #Lab Machine Definition 35 | $postInstallActivity = Get-LabPostInstallationActivity -ScriptFileName mapdc.ps1 -DependencyFolder $labSources\PostInstallationActivities\Custom 36 | Add-LabMachineDefinition -Name "CL01" -IpAddress 192.168.123.100 -Memory 2GB -OperatingSystem 'Windows 10 Enterprise Evaluation' -PostInstallationActivity $postInstallActivity 37 | Add-LabMachineDefinition -Name "CL02" -IpAddress 192.168.123.101 -Memory 2GB -OperatingSystem 'Windows 10 Enterprise Evaluation' -PostInstallationActivity $postInstallActivity 38 | Add-LabMachineDefinition -Name "CL03" -IpAddress 192.168.123.102 -Memory 2GB -OperatingSystem 'Windows 10 Enterprise Evaluation' -PostInstallationActivity $postInstallActivity 39 | 40 | #Install Lab 41 | Install-Lab 42 | 43 | #Get RDP Files 44 | Get-LabVMRdpFile -UseLocalCredential -All -Path $labSources 45 | 46 | #Deployment Summary 47 | Show-LabDeploymentSummary -Detailed 48 | 49 | #Show Labs 50 | Get-Lab -List 51 | 52 | #Remove Lab 53 | Remove-Lab -Path C:\ProgramData\AutomatedLab\Labs\TechLab -------------------------------------------------------------------------------- /CustomLabRessources/CopyFiles/CreateADUsers.ps1: -------------------------------------------------------------------------------- 1 | Import-Module ActiveDirectory 2 | 3 | cd C:\CopyFiles 4 | 5 | #Import CSV: 6 | $ADUsers = Import-Csv ".\users.csv" -Delimiter ";" 7 | 8 | #UPN-Suffix 9 | $UPN = "tech.pri" 10 | 11 | #Loop to create users 12 | foreach ($User in $ADUsers) { 13 | 14 | #Not absolutely necessary, but more elegant var designations 15 | $username = $User.username 16 | $password = $User.password 17 | $firstname = $User.firstname 18 | $lastname = $User.lastname 19 | $initials = $User.initials 20 | $email = $User.email 21 | $streetaddress = $User.streetaddress 22 | $city = $User.city 23 | $zipcode = $User.zipcode 24 | $state = $User.state 25 | $telephone = $User.telephone 26 | $jobtitle = $User.jobtitle 27 | $department = $User.department 28 | 29 | #Warning, if user already exists! 30 | if (Get-ADUser -Filter { SamAccountName -eq $username }) { 31 | Write-Warning "A user account with username $username already exists in Active Directory." 32 | } 33 | else { 34 | 35 | #If user does not exist yet: 36 | New-ADUser ` 37 | -SamAccountName $username ` 38 | -UserPrincipalName "$username@$UPN" ` 39 | -Name "$firstname $lastname" ` 40 | -GivenName $firstname ` 41 | -Surname $lastname ` 42 | -Initials $initials ` 43 | -Enabled $True ` 44 | -DisplayName "$lastname, $firstname" ` 45 | -City $city ` 46 | -PostalCode $zipcode ` 47 | -Company $company ` 48 | -State $state ` 49 | -StreetAddress $streetaddress ` 50 | -OfficePhone $telephone ` 51 | -EmailAddress $email ` 52 | -Title $jobtitle ` 53 | -Department $department ` 54 | -AccountPassword (ConvertTo-secureString $password -AsPlainText -Force) -ChangePasswordAtLogon $True 55 | 56 | #Output: 57 | Write-Host "The user account $username is created." -ForegroundColor Cyan 58 | } 59 | } -------------------------------------------------------------------------------- /CustomLabRessources/CopyFiles/DeployWebsite.ps1: -------------------------------------------------------------------------------- 1 | Cd C:\CopyFiles 2 | New-Item -ItemType Directory -Name 'MyWebsite' -Path 'C:\' 3 | Copy-Item -Path .\index.html -Destination C:\MyWebsite 4 | New-IISSite -Name 'MyWebsite' -PhysicalPath 'C:\MyWebsite\' -BindingInformation "*:8088:" 5 | 6 | -------------------------------------------------------------------------------- /CustomLabRessources/CopyFiles/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | AutomatedLab and PowerShell 5 | 6 | 7 |

IIS Administration with PowerShell Demo

8 |

Thank you for visiting this page!

9 | 10 |

Stay tuned with PowerShell and AutomatedLab!

11 |

First Steps

12 |

Keep calm and learn PowerShell.

13 | 14 | -------------------------------------------------------------------------------- /CustomLabRessources/CopyFiles/mapdc.ps1: -------------------------------------------------------------------------------- 1 | #Credentials 2 | [string]$Username = "Administrator" 3 | [string]$Password = "P@ssw0rd" 4 | [securestring]$secPass = ConvertTo-SecureString $Password -AsPlainText -Force 5 | $Cred = New-Object System.Management.Automation.PSCredential($Username,$secPass) 6 | 7 | #Drive Mapping 8 | New-PSDrive -Name U -PSProvider FileSystem -Root \\DC01\C$ -Credential $Cred -Persist -------------------------------------------------------------------------------- /CustomLabRessources/CopyFiles/users.csv: -------------------------------------------------------------------------------- 1 | FirstName;Initials;Lastname;Username;Email;StreetAddress;City;ZipCode;Country;Department;Password;Telephone;JobTitle 2 | Max;MF;Pane;Max.Pane;Max.Pane@tech.pri;21 Baker St;Dublin;NW1 6XE;Ireland;IT;Q+/7_]Tc;44123456780;Engineer 3 | Piers;PB;Dodge;Piers.Dodge;Piers.Dodge@tech.pri;21 Baker St;Dublin;NW1 6XE;Ireland;IT;RW-cn3N);44123456781;Manager 4 | Kylie;KD;Davidson;Kylie.Davidson;Kylie.Davidson@tech.pri;21 Baker St;Dublin;NW1 6XE;Ireland;IT;3VKr2.Wm;44123456782;Engineer 5 | Richard;RG;Grant;Richard.Grant;Richard.Grant@tech.pri;21 Baker St;Dublin;NW1 6XE;Ireland;IT;)N3ZYJvS;44123456783;Teamleader 6 | Boris;BC;Jones;Boris.Jones;Boris.Jones@tech.pri;21 Baker St;Dublin;NW1 6XE;Ireland;IT;9ZesQ]pq;44123456784;Engineer 7 | Nicholas;NM;Murray;Nicholas.Murray;Nicholas.Murray@tech.pri;21 Baker St;Dublin;NW1 6XE;Ireland;IT;KX*rB72p;44123456785;Manager 8 | Leonard;LC;Clark;Leonard.Clark;Leonard.Clark@tech.pri;21 Baker St;Dublin;NW1 6XE;Ireland;IT;AJ+(}c3$;44123456786;Engineer 9 | Ruth;RD;Dickens;Ruth.Dickens;Ruth.Dickens@tech.pri;21 Baker St;Dublin;NW1 6XE;Ireland;IT;Jgv4{Bb$;44123456787;Engineer 10 | Jonathan;JF;Fisher;Jonathan.Fisher;Johnathan.Fisher@tech.pri;21 Baker St;Dublin;NW1 6XE;Ireland;IT;u*PQJAx5;44123456788;Engineer 11 | Grace;GR;Rees;Grace.Rees;Grace.Rees@tech.pri;21 Baker St;Dublin;NW1 6XE;Ireland;IT;w([6p&Kt;44123456789;Engineer -------------------------------------------------------------------------------- /CustomLabRessources/Custom/mapdc.ps1: -------------------------------------------------------------------------------- 1 | #Credentials 2 | [string]$Username = "Administrator" 3 | [string]$Password = "P@ssw0rd" 4 | [securestring]$secPass = ConvertTo-SecureString $Password -AsPlainText -Force 5 | $Cred = New-Object System.Management.Automation.PSCredential($Username,$secPass) 6 | 7 | #Drive Mapping 8 | New-PSDrive -Name U -PSProvider FileSystem -Root \\DC01\C$ -Credential $Cred -Persist -------------------------------------------------------------------------------- /Links.md: -------------------------------------------------------------------------------- 1 | AutomatedLab 2 | ------------ 3 | https://automatedlab.org 4 | 5 | https://github.com/AutomatedLab/AutomatedLab 6 | 7 | **Download** 8 | https://github.com/AutomatedLab/AutomatedLab/releases 9 | 10 | **Getting started** 11 | https://automatedlab.org/en/latest/Wiki/Basic/gettingstarted/ 12 | 13 | https://automatedlab.org/en/latest/Wiki/Advanced/automatedlabconfig/ 14 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # AutomatedLab and PowerShell 2 | Deploy automated test or training environment with PowerShell! 3 | -------------------------------------------------------------------------------- /testResults.xml: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | --------------------------------------------------------------------------------