- Set up nested Hyper-V virtualization - Mon, May 20 2019
- Set up a Hyper-V home lab with the AutomatedLab PowerShell module - Thu, May 9 2019
To get started automating your home lab with the AutomatedLab PowerShell module, we first need to make sure we've got a couple of things up and running ahead of time.
- Windows 10: check out the 4sysops article on enabling Hyper-V
- Windows Server: Install Hyper-V using Server Manager
- The AutomatedLab PowerShell Module
Install-Module AutomatedLab -AllowClobber
Before you can deploy your first lab, you'll need to set up AutomatedLab so that it knows where to find the appropriate ISO files. To do this, you must first create what it refers to as the LabSources folder:
After the command finishes, it will output the location of the folder it creates. This is where AutomatedLab will look for installation files for operating systems and supported applications.
If you don't have any operating system ISO files, be sure to check out Microsoft's evaluation website . I grabbed the Windows Server 2019 ISO for this demo. Next, copy the ISO files of the operating system you want to deploy into the \ISOs folder inside of LabSources:
Now you'll want to make sure AutomatedLab recognizes them by running:
Get-LabAvailableOperatingSystem -Path C:\LabSources
Be sure to take note of the OperatingSystemName values; you're going to use these in your script for building your lab.
Building your first lab
Now that you have the AutomatedLab module installed and your operating system ISO files ready, we can build the first lab! To get started, open up your PowerShell script editor of choice. I prefer VS Code, but the Integrated Scripting Environment (ISE) will work fine if you don't want the hassle of installing another program.
In your script, you want to start by defining a Lab Definition—this is the metadata for your lab. As a very basic example, you only need to define a lab name and your virtualization engine, but you can get pretty fancy and set the path and limit resources for the entire lab if desired.
The easiest example to start with is:
New-LabDefinition -Name 'FirstLab' -DefaultVirtualizationEngine HyperV
You'll notice it did a couple of things:
- Put the lab definition files in the default directory of C:\ProgramData\AutomatedLab\Labs
- Ran an update on the SysInternals Suite tools since AutomatedLab uses those extensively
- Rescanned the operating system files
Once you have the lab definition configured, you can start adding virtual machines (VMs) to your lab with the Add-LabMachineDefinition cmdlet.
It is important to note that by running this command you are not creating a VM; you are simply adding the data to the lab definition so that AutomatedLab will know what to create when you install the lab.
We can add a root domain controller; notice I'm using an operating system from before:
Add-LabMachineDefinition -Name DC01 -OperatingSystem 'Windows Server 2019 Datacenter Evaluation (Desktop Experience)' -Roles RootDC -DomainName 'theposhwolf.com'
By specifying RootDC as the role for this server, it will automatically install the specified domain. Also, since I didn't select a network, it assigns one.
Then, if we want to add a member server with no role, we can run:
Add-LabMachineDefinition -Name Member01 -OperatingSystem 'Windows Server 2019 Datacenter Evaluation (Desktop Experience)' -IsDomainJoined -DomainName 'theposhwolf.com'
This defines a member server in the specified domain:
Now that we've defined our two servers, we can have AutomatedLab deploy our lab by running:
If this is your first time running this command, and, like me, you chose not to specify a storage drive for your VMs in New-LabDefinition, AutomatedLab will run some tests to find the best storage drive.
After it completes its testing, it will also need to adjust some PowerShell remoting settings so it can talk to the VMs once they start up. If you are running your lab on a work computer, chances are you won't be able to adjust many of the settings, but for a home system or a dedicated lab server, these are fine.
Now this will take some time to run because it will be creating the VMs and setting up Active Directory with any other roles that you defined.
After it finishes, assuming you have the Hyper-V Manager installed, you can launch that and admire your easily built VMs!
If you didn't specify a password, the default is: Somepass1.
Next, you can have AutomatedLab clean everything up by running:
If you save your script as a .ps1 file, any time you need to rebuild that lab, all you need to do is to run the script, wait the 10 to 15 minutes, and you'll have a lab ready to go!
If you'd like to see some of the advanced features of AutomatedLab, be sure to check out their Github repository.