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.

Anthony Howell

Anthony has been an IT pro since 2009, and he now works as a PowerShell consultant who focuses on automation. You can find Anthony at theposhwolf.com or on Twitter at @theposhwolf.

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

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:

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:

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:

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:

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:

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.

Join the 4sysops PowerShell group!

Your question was not answered? Ask in the forum!

6+

Users who have LIKED this post:

  • avatar
  • avatar
  • avatar
Share
12 Comments
  1. Chris 7 months 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.

     

    1+

    Users who have LIKED this comment:

    • avatar
    • Leos Marek 7 months 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

      2+

      Users who have LIKED this comment:

      • avatar
      • avatar
      • Chris 6 months 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?

        0

        • Leos Marek 6 months 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).

          0

  2. Swapnil Kambli 7 months ago

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

    0

  3. Chris 6 months 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.

    0

    • Author
      Anthony Howell 6 months ago

      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?

      0

  4. Chris 6 months 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

    0

    • Swapnil Kambli 6 months ago

      Hi Chris,

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

      And then start over.

       

      0

    • Swapnil Kambli 6 months ago

      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. 

      0

  5. David Gross 6 months 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.

    1+

    Users who have LIKED this comment:

    • avatar
  6. thedavecarroll 6 months ago

    @David Gross

    I just ran the following:

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

    Hope that helps.

    2+

    Users who have LIKED this comment:

    • avatar

Leave a reply

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

*

© 4sysops 2006 - 2019

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