The AutomatedLab PowerShell module lets you deploy complex labs on Hyper-V and Azure with PowerShell. In this post, I'll show how you can quickly set up a home lab with AutomatedLab.
Avatar
Latest posts by Anthony Howell (see all)

Getting started

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.

  1. Hyper-V
    1. Windows 10: check out the 4sysops article on enabling Hyper-V
    2. Windows Server: Install Hyper-V using Server Manager
  2. 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:

New-LabSourcesFolder
Create the lab sources folder

Create the lab sources 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:

The folder with your ISO files

The folder with your ISO files

Now you'll want to make sure AutomatedLab recognizes them by running:

Get-LabAvailableOperatingSystem -Path C:\LabSources
Listing the operating systems in the Server 2019 ISO

Listing the operating systems in the Server 2019 ISO

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
Creating the lab definition

Creating the lab definition

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.

Adding a domain controller to the lab definition

Adding a domain controller to the lab definition

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:

Adding a member server to the lab definition

Adding a member server to the lab definition

Now that we've defined our two servers, we can have AutomatedLab deploy our lab by running:

Install-Lab

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.

The final product, up and running

The final product, up and running

Next, you can have AutomatedLab clean everything up by running:

Remove-Lab

Looking forward

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.

avataravataravatar
13 Comments
  1. Avatar
    Chris (Rank 3) 5 years ago

    Anthony,

    This is a very convenient tool for automating the process of building a Hyper-V lab. I followed the steps and was succesful in creating the VMs and connecting to them. I'm running into an issue joining my host machine to the domain though, I receive the following error:

    The following error occurred when DNS was queried for the service location (SRV) resource record used to locate an Active Directory Domain Controller (AD DC) for domain "homelab.local":

    The error was: "DNS name does not exist."
    (error code 0x0000232B RCODE_NAME_ERROR)

     

    One thing to note: I don't have access to the router that the host machine is connected to, as I use the WiFi provided by my apartment complex.

     

    avatar
    • Avatar
      Leos Marek (Rank 4) 5 years ago

      Chris,

      you will need to modify your host DNS settings to point to the created Domain controller, not to your router. Actually you dont need to join the Hyper-V host to your newly build domain. It will work even without it.

      Leos

      avataravatar
      • Avatar
        Chris (Rank 3) 5 years ago

        Yea, I still want to some add devices to the domain for experimentation purposes (I'm taking my MCSA soon). Does the DC need to have a static IP?

        • Avatar
          Leos Marek (Rank 4) 5 years ago

          You may add as many devices to the domain as you like, you just need to configure proper DNS server on the device (your DC) so it finds proper SRV record for your domain. 

          Yes, normally DNS/DC have static IPs as you need to configure this on a client somehow (manually or via DHCP).

  2. Avatar

    With further development, AutomatedLab utility can be considered for vagrant replacement at least for Microsoft Platform.

  3. Avatar
    Chris (Rank 3) 5 years ago

    How do i get the lab to actually be permanent? Seems like it deletes itself after a day yet when I go to try and recreate it, it doesn't let me use the same server names. Tells me the server name is already assigned.

    • Avatar Author

      I honestly haven't seen that issue before. I've got several labs that have been around for weeks.

      Are the VMs not showing up in Hyper-V Manager after a day? Or what are you seeing?

  4. Avatar
    Chris (Rank 3) 5 years ago

    I’m getting this error message when I try to recreate the machines by running Add-LabMachineDefinition -Name DCSRV -OperatingSystem ‘Windows Server 2019 Standard Evaluation
    (Desktop Experience)’ -Roles RootDC -DomainName ‘homelab.local’

    Write-Error : A machine with the name 'DCSRV' does already exist
    At C:Program FilesWindowsPowerShellModulesAutomatedLabDefinition5.9.0AutomatedLabDefinition.psm1:2055 char:13
    +             Write-Error $errorMessage
    +             ~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : NotSpecified: (:) [Write-Error], WriteErrorException
        + FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,Write-Error

    Write-LogFunctionExitWithError : Add-LabMachineDefinition…leaving: A machine with the name 'DCSRV' does already exist
    At C:Program FilesWindowsPowerShellModulesAutomatedLabDefinition5.9.0AutomatedLabDefinition.psm1:2056 char:13
    +             Write-LogFunctionExitWithError -Message $errorMessage
    +             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : NotSpecified: (:) [Write-Error], WriteErrorException
        + FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,Write-LogFunctionExitWithError

    • Avatar

      Hi Chris,

      Please run Remove-Lab to remove the entries from the config files and clean environment. 

      And then start over.

       

    • Avatar

      Also, the error implies VMs were no deleted through Automated Lab. The Remove function of Automated Lab removes the local configuration file entries as well. 

  5. Avatar
    David Gross 5 years ago

    This is really great stuff!

    I do have a question, though:

    Is there a way to specify the location of the Lab Sources folder? It looks like it defaults to C:\LabSources and it is unclear if you can specify a different location.. I have limited room on my C: drive and would rather place it on my Data volume.

    avatar
  6. Avatar
    thedavecarroll 5 years ago

    @David Gross

    I just ran the following:

    New-LabSourcesFolder -DriveLetter D

    You can always use the Get-Help cmdlet to see what parameters are available to commands.

    Get-Help New-LabSourcesFolder
    
    NAME
        New-LabSourcesFolder
    
    SYNTAX
        New-LabSourcesFolder [[-DriveLetter] <string>] [-Force] [-WhatIf] [-Confirm]  [<CommonParameters>]
    
    
    ALIASES
        None
    
    
    REMARKS
        None

    Hope that helps.

    avatar
  7. Avatar
    dec1slh 2 years ago

    Is there a way to add a vm to a lab after it has been created and used?  I see the new-labvm module.  I wonder if I can add it the the definition and then use the new-labvm command.

Leave a reply

Your email address will not be published. Required fields are marked *

*

© 4sysops 2006 - 2023

CONTACT US

Please ask IT administration questions in the forums. Any other messages are welcome.

Sending

Log in with your credentials

or    

Forgot your details?

Create Account