Create a lab machine

Create a lab machine

This comprehensive guide will walk you through setting up Hyper-V on your Windows 11 computer using PowerShell commands, as well as how to utilize the Windows 11 development environment available via the Quick Create feature. By following these steps, you’ll gain all the knowledge needed to install and run Hyper-V efficiently on your system.

All the code and information provided on this website are offered “as is” without any guarantees or warranties of any kind. Although the code and information are tested, we do not warrant that the code is error-free or that it will meet your specific requirements. Use the code at your own risk. We disclaim all liability for any damages or losses arising from the use or inability to use the provided materials.

Enable Hyper-V


First, we need to verify whether Hyper-V is enabled on your computer.
There are multiple ways to check this, but for consistency, this guide will use PowerShell whenever possible.

You probably need like 100 GB of free disk space to be able to do this.
The download is almost 22 GB and then you need disk for the installation and the lab.

And you will need some free memory as well.
I use 4096 MB and It’s okay for a Lab Machine for PowerShell and Visual Studio Code.

Start by opening Visual Studio Code or PowerShell ISE with “Run as Administrator” privileges.

Next, let’s check if the Hyper-V feature is currently enabled.
Write or Copy and paste the code below to your PowerShell editor and run the code.

Get-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V

If you get this status you need to enable it.

If you get this status you don’t need to enable it.

To enable it we just need to write or copy and paste this code (all on the same line):

Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V -All

This will enable Hyper-V with all subfeatures and tools.
When prompted to restart, it is best to press Y and restart.


Quick Create

Now that the Hyper-V feature is installed, we can open the Hyper-V Quick Create tool by searching for Hyper-V Quick Create.

Make sure to open it as an administrator.

Then just click on Windows 11 dev environment and after that Create Virtual Machine.

First of all the Quick Create will download the image.

And then the image will be extracted.

When Quick Create is finished, you will have the option to connect or edit settings.


Connect and start

Just press Start!

Waiting a bit longer

Sign In


Click on Sign In

Some more waiting

And then we are good to go with a fully installed Windows 11 for development.

Setup the lab computer

This guide will show you how to set up and install all tools needed for PowerShell and Visual Studio Code in the Lab Machine.

Language

First, open PowerShell ISE as Administrator.

Click the arrow next to Script to open the Editor in PowerShell ISE.
Then close the Commands view on the right to have more space for scripting.

First of all I want to set all language settings to Swedish.
Just copy and past the code below and run it to do the changes.
You can do it bit by bit or all at once.

This can be done in different ways but I like my scripts to have more checks built in.
So this is not the easiest way ๐Ÿ˜Š

We start with a check for Run As Administrator and a Clear-Host.

# Check if the script is running with administrative privileges
#Requires -RunAsAdministrator

# Clear the terminal part
Clear-Host

Then we set the input method to Swedish if it is not already.

# Set the default input method to Swedish (Sweden) - Keyboard layout: Swedish
if ((Get-WinDefaultInputMethodOverride).InputMethodTip -ne "041D:0000041D") {
    Set-WinDefaultInputMethodOverride -InputTip "041D:0000041D"
}

If you want another input method you can look at the Default input profiles (input locales) in Windows page at Microsoft Learn for more language codes.

You just need to use the same language codes for the Get and for the Set.

And now we change the user language list to Swedish.

# Set the user language list to Swedish (Sweden)
if ((Get-WinUserLanguageList).LanguageTag -notcontains "sv-SE") {
    Set-WinUserLanguageList -LanguageList "sv-SE" -Force
}

For this one you will get this warning and it’s normal:

WARNING: If the Windows Display Language has changed, it will take effect after the next sign-in.

And to set the system locale to Swedish we write:

# Set the system locale to Swedish (Sweden)
if ((Get-WinSystemLocale).Name -ne "sv-SE") {
    Set-WinSystemLocale -SystemLocale "sv-SE"
}

Setting user locale to Swedish:

# Set the user locale to Swedish (Sweden)
if ((Get-Culture).Name -ne "sv-SE") {
    Set-Culture -CultureInfo "sv-SE"
}

Home location:

# Set the home location to Sweden
if ((Get-WinHomeLocation).GeoID -ne "221") {
    Set-WinHomeLocation -GeoID "221"
}

For a table of GeoIDs, see Table of Geographical Locations at Microsoft Learn.

The last language setting is the Time Zone:

# Ensure the time zone is set to W. Europe Standard Time (CET/CEST) 
if ((Get-TimeZone).Id -ne "W. Europe Standard Time") {
    Set-TimeZone -Id "W. Europe Standard Time"
}

To get another time zone, you can use the cmdlet Get-TimeZone.

Get-TimeZone -ListAvailable

The last step for the Language section is to restart the Lab computer.
This can be done manually or with PowerShell.

Using PowerShell for a quick restart, we do the following:

Restart-Computer -Force -Confirm:$false

Now we have the following code:

<#
.SYNOPSIS
    Configures Windows system and user locale settings for Swedish (Sweden).

.DESCRIPTION
    This script sets the following to Swedish (Sweden):
    - Default input method (keyboard layout)
    - User language list
    - System locale
    - User locale
    - Home location (region)
    - Time zone (W. Europe Standard Time)
    The script will restart the computer to apply changes.

.NOTES
    Requires administrative privileges.
    Some changes may require a restart to take effect.
#>

# Check if the script is running with administrative privileges
#Requires -RunAsAdministrator

# Clear the terminal part
Clear-Host

# Set the default input method to Swedish (Sweden) - Keyboard layout: Swedish
if ((Get-WinDefaultInputMethodOverride).InputMethodTip -ne "041D:0000041D") {
    Set-WinDefaultInputMethodOverride -InputTip "041D:0000041D"
}

# Set the user language list to Swedish (Sweden)
if ((Get-WinUserLanguageList).LanguageTag -notcontains "sv-SE") {
    Set-WinUserLanguageList -LanguageList "sv-SE" -Force
}

# Set the system locale to Swedish (Sweden)
if ((Get-WinSystemLocale).Name -ne "sv-SE") {
    Set-WinSystemLocale -SystemLocale "sv-SE"
}

# Set the user locale to Swedish (Sweden)
if ((Get-Culture).Name -ne "sv-SE") {
    Set-Culture -CultureInfo "sv-SE"
}

# Set the home location to Sweden
if ((Get-WinHomeLocation).GeoID -ne "221") {
    Set-WinHomeLocation -GeoID "221"
}

# Ensure the time zone is set to W. Europe Standard Time (CET/CEST) 
if ((Get-TimeZone).Id -ne "W. Europe Standard Time") {
    Set-TimeZone -Id "W. Europe Standard Time"
}

Restart-Computer -Force -Confirm:$false

PowerShell 7

Now that the language has been successfully set, we can move forward with the next step, which is installing PowerShell 7. This installation is essential to enable and run labs that specifically require PowerShell 7 for their execution and functionality.

The simplest and officially recommended method by Microsoft to install PowerShell 7 on Windows is by using WinGet.

However, this method will only be effective if the lab computer is completely and thoroughly updated with the latest system updates. Without having the most recent updates installed, WinGet will not operate correctly and may encounter various issues or fail to function altogether.

The simplest and most straightforward way to ensure your system is fully up to date is to manually navigate to the Check for Updates section and carefully install all available updates. This process should include not only the critical and recommended updates but also optional ones, such as those related to .NET framework components, which can be essential for certain applications to function properly.

Start Windows PowerShell with Administrator privileges to ensure you have the necessary permissions.

Then enter the following command:

winget list --id Microsoft.PowerShell

After reviewing the MS Store terms carefully, proceed by pressing the Y key to indicate your agreement and acceptance of all the conditions outlined.

Now we can start PowerShell ISE as administrator and write the following code:

# Check if the script is running with administrative privileges
#Requires -RunAsAdministrator

# Clear the terminal part
Clear-Host

# Check if PowerShell 7 is installed using winget
$Pwsh = winget list --id Microsoft.PowerShell | Select-String "PowerShell"
if ($Pwsh) {
    Write-Output "PowerShell 7 is installed."
} else {
    Write-Output "PowerShell 7 is NOT installed."
    # Install PowerShell 7
    winget install --id Microsoft.PowerShell --source winget --accept-source-agreements --accept-package-agreements
}


Visual Studio Code

Now it is time to move forward and proceed with the installation of Visual Studio Code on the Lab computer, ensuring that we have the latest tools ready for our development work.

We will perform this installation process using WinGet along with PowerShell, following the same method we previously used when installing PowerShell 7, to maintain consistency and efficiency in our setup steps.

# Check if the script is running with administrative privileges
#Requires -RunAsAdministrator

# Clear the terminal part
Clear-Host

# Install Visual Studio Code
# Check if Visual Studio Code is installed using winget
$VsCode = winget list --id Microsoft.VisualStudioCode | Select-String "Visual Studio Code"
if ($VsCode) {
    Write-Output "Visual Studio Code is installed."
} else {
    Write-Output "Visual Studio Code is NOT installed."
    # Install Visual Studio Code
    winget install Microsoft.VisualStudioCode --accept-source-agreements --accept-package-agreements
}


VSCode Extensions

Now we are fully prepared and ready to start working with our development environment.

HOWEVER, Visual Studio Code (VSCode) becomes much more powerful and enjoyable to use when enhanced with some useful extensions, and I personally recommend these 5 essential extensions as a great starter kit to improve your workflow.

PowerShell for Visual Studio Code

This extension allows you to seamlessly integrate full PowerShell support within Visual Studio Code, making scripting and command execution much easier and more efficient.

VSCode-Icons

This extension adds visually appealing and distinctive icons to the Explorer view, helping you quickly identify file types and folders.
After installing, you must enable it within the extensions panel to activate the icon set.

Without:

With:


CodeSnap

Takes a clear and nice screenshot of your code and saves it to a file on your computer.

Press Ctrl-Shift-P to open the Command Palette, then type CodeSnap in the search bar, and select the CodeSnap option from the list.

After that, simply highlight the portion of code you want to capture, and the tool will create a neat screenshot for you.

Then press the shutter button to capture the image and save the screenshot to your desired location.
The picture shown below is taken from the CodeSnap extension.


GitHub CoPilot

GitHub CoPilot provides you with the incredible power of artificial intelligence directly within Visual Studio Code, making your coding experience much more efficient and enjoyable.

All you need to start using this amazing tool is a simple GitHub account, which enables you to access its full range of features without any hassle.

In my opinion, it is especially useful for assisting with the creation of documentation and for debugging code, offering valuable suggestions and insights that can save time and improve the quality of your projects.

XML Tools

XML Tools by Josh Johnson.

I frequently work with XML files in my projects, and this tool has proven to be incredibly helpful for me. It assists greatly with the formatting of XML files whenever it is needed, making the process much smoother and more efficient.

Install Extensions

To install extensions, you have several options available. You can easily do it directly from Visual Studio Code using the graphical user interface (GUI), which provides a user-friendly way to browse and add extensions. Alternatively, if you prefer using the command line, you can install extensions through PowerShell or from a Command Prompt window running with administrator privileges. Each method allows you to efficiently manage your extensions according to your preferred workflow.

# Install PowerShell Extension
code --install-extension ms-vscode.PowerShell

# Install VSCode-Icons Extension
code --install-extension vscode-icons-team.vscode-icons

# Install CodeSnap Extension
code --install-extension adpyke.codesnap

# Install GitHub CoPilot incl CoPilot Chat Extension
code --install-extension github.copilot

# Install XML Tools by Josh Johnson
code --install-extension dotjoshjohnson.xml

The End

This marks the official conclusion of this comprehensive and detailed guide.

Up to this point, we have successfully completed the setup of a Lab computer that is fully equipped with the latest version of PowerShell 7 (7.5). In addition, we have installed the powerful and versatile Visual Studio Code editor along with five carefully selected and highly useful extensions.

All of these components are running smoothly and efficiently within a Hyper-V virtual environment. Furthermore, the system has been configured with the appropriate language settings to significantly enhance overall usability and user experience.

It is my sincere hope that this guide will assist you in setting up your Lab environment quickly and efficiently, allowing you to have a strong and effective start to your Lab experience.


Leave a Reply

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

The PowerAdmin
Privacy Overview

This website uses cookies so that we can provide you with the best user experience possible. Cookie information is stored in your browser and performs functions such as recognising you when you return to our website and helping our team to understand which sections of the website you find most interesting and useful.