Skip to content

Instantly share code, notes, and snippets.

@nyanhp
Last active December 14, 2017 09:07
Show Gist options
  • Save nyanhp/ee198ce88416db90cbb58cf41a180861 to your computer and use it in GitHub Desktop.
Save nyanhp/ee198ce88416db90cbb58cf41a180861 to your computer and use it in GitHub Desktop.
AutomatedLabINCEPTION
$labname = 'Inception'
New-LabDefinition -Name $labname -DefaultVirtualizationEngine HyperV
Add-LabMachineDefinition -Name DreamLayer1 -Memory 8GB -OperatingSystem 'Windows Server 2016 SERVERSTANDARDCORE'
Install-Lab
Get-Vm DreamLayer1 | stop-Vm -Passthru | Set-VMProcessor -ExposeVirtualizationExtensions $true
Start-LabVm DreamLayer1
Copy-LabFileItem -Path $labsources\isos\en_windows_server_2016_x64_dvd_9327751.iso -ComputerName DreamLayer1 -DestinationFolderPath C:\Labsources\ISOs\
$image = Get-ChildItem -Path (Get-Lab).Target.Path -Filter "BASE_$((Get-LabVm DreamLayer1).OperatingSystem.OperatingSystemName -replace ' ')*"
Copy-LabFileItem -Path $image.FullName -ComputerName DreamLayer1 -DestinationFolderPath C:\AutomatedLab-VMs\
$modules = @('AutomatedLab')
$modules += (Get-MOdule AutomatedLab -ListAvailable).RequiredModules
foreach ($module in $modules)
{
$m = Get-Module $module -ListAvailable | Select -First 1
Send-ModuleToPSSession -Module $m -Session (New-LabPSSession DreamLayer1)
}
Install-LabWindowsFeature -ComputerName DreamLayer1 -FeatureName Hyper-V, Hyper-V-PowerShell -IncludeAllSubFeature
Restart-LabVM DreamLayer1 -Wait
Start-Sleep -Seconds 5 # Dreaming...
Invoke-LabCommand -ActivityName 'entering first dream layer' -ComputerName DreamLayer1 -ScriptBlock {
$labname = 'Inception'
New-LabDefinition -Name $labname -DefaultVirtualizationEngine HyperV -ErrorAction SilentlyContinue
Add-LabMachineDefinition -Name DreamLayer2 -Memory 5GB -OperatingSystem 'Windows Server 2016 SERVERSTANDARDCORE'
Install-Lab
Get-Vm DreamLayer2 | stop-Vm -Passthru | Set-VMProcessor -ExposeVirtualizationExtensions $true
Start-LabVm DreamLayer2
Copy-LabFileItem -Path $labsources\isos\en_windows_server_2016_x64_dvd_9327751.iso -ComputerName DreamLayer2 -DestinationFolderPath C:\Labsources\ISOs\
$image = Get-ChildItem -Path (Get-Lab).Target.Path -Filter "BASE_$((Get-LabVm DreamLayer2).OperatingSystem.OperatingSystemName -replace ' ')*"
Copy-LabFileItem -Path $image.FullName -ComputerName DreamLayer2 -DestinationFolderPath C:\AutomatedLab-VMs\
$modules = @('AutomatedLab')
$modules += (Get-MOdule AutomatedLab -ListAvailable).RequiredModules
foreach ($module in $modules)
{
$m = Get-Module $module -ListAvailable | Select -First 1
Send-ModuleToPSSession -Module $m -Session (New-LabPSSession DreamLayer2)
}
Install-LabWindowsFeature -ComputerName DreamLayer2 -FeatureName Hyper-V, Hyper-V-PowerShell -IncludeAllSubFeature
Restart-LabVM DreamLayer2 -Wait
}
Start-Sleep -Seconds 5 # Dreaming...
Invoke-LabCommand -ActivityName 'Entering first dream layer' -ComputerName DreamLayer1 -ScriptBlock {
Import-Lab Inception -NoValidation
Invoke-LabCommand -ActivityName 'entering second dream layer' -ComputerName DreamLayer2 -ScriptBlock {
$labname = 'DreamLayer2'
New-LabDefinition -Name $labname -DefaultVirtualizationEngine HyperV -ErrorAction SilentlyContinue
Add-LabDomainDefinition -Name contoso.com -AdminUser Install -AdminPassword Somepass1
Set-LabInstallationCredential -Username Install -Password Somepass1
Add-LabMachineDefinition -Name Cobb -Memory 512MB -Roles RootDC -OperatingSystem 'Windows Server 2016 SERVERSTANDARDCORE' -DomainName contoso.com
Install-Lab
}
}
Start-Sleep -Seconds 5 # Dreaming...
Invoke-LabCommand -ComputerName DreamLayer1 -ScriptBlock {
Import-Lab inception -NoValidation
Invoke-LabCommand -ComputerName DreamLayer2 -ScriptBlock {
Import-Lab DreamLayer2 -NoValidation
Invoke-LabCommand -ComputerName (Get-LabVm) -ScriptBlock {
$hyperVisor = (get-item "HKLM:\SOFTWARE\Microsoft\Virtual Machine\Guest\Parameters").GetValue("HostName")
"Hello from $env:COMPUTERNAME running on $hyperVisor"
} -PassThru
$hyperVisor = (get-item "HKLM:\SOFTWARE\Microsoft\Virtual Machine\Guest\Parameters").GetValue("HostName")
"Hello from $env:COMPUTERNAME running on $hyperVisor"
} -PassThru
$hyperVisor = (get-item "HKLM:\SOFTWARE\Microsoft\Virtual Machine\Guest\Parameters").GetValue("HostName")
"Hello from $env:COMPUTERNAME running on $hyperVisor"
} -PassThru
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment