If you often need a test environment, for example to try something out in an Active Directory environment, you don’t have to set it up manually. With AutomatedLab, you can simply define a test environment and set it up automatically. AutomatedLab is a free PowerShell module.
I also demonstrate the module in this video on YouTube.
Installation
The module should also work on Linux and macOS, but so far I’ve only used it on Windows.
You can find installation instructions in the official documentation: https://automatedlab.org/en/latest/Wiki/Basic/install/
However, I ran the following:
| |
ISO Files for the Lab Environment
Inside the “LabSources” folder, there is an “ISOs” folder. The ISO files for automatically installing the operating systems must be placed there.
If you don’t have any ISOs handy, you can also download free evaluation copies of Windows 11 or Windows Server from Microsoft: https://www.microsoft.com/en-us/evalcenter
You can then use PowerShell to check if the ISOs are recognized correctly:
| |
Define and Set Up the Lab
Here is an example of a simple test environment. If you don’t define a password, Somepass1 will be used as the default password.
To improve readability, I supplied the parameter values using hashtables and splatting. Of course, you can also use the standard -ParameterName "ParameterValue" syntax if you prefer.
| |
I saved the script as MyLab.ps1. One important thing: the script must be run with administrator privileges so it can interact with Hyper-V. You can either start VS Code (or the PowerShell ISE) with administrator privileges, or open a separate PowerShell window with administrator privileges.
| |
This takes a little while, depending on your system and the lab machines you selected. At the end, you’ll see a summary. If everything completed successfully, you can now use the environment.
Delete the Lab
When you’re done with your tests, you can simply delete the environment. If you closed your PowerShell window in the meantime, you can import the lab into the session again with Import-Lab Demotenant (use your lab name instead of “Demotenant”).
To delete it, simply run Remove-Lab.
More Possibilities and Options
AutomatedLab can do much more, for example, install Microsoft SQL Server or set up multiple AD domains and connect them with trusts. You can also control the IP range used, passwords, and much more. For more information check out the documentation.
