Skip to content

Files

Latest commit

cdca69b · Mar 27, 2022

History

History
107 lines (83 loc) · 4.14 KB

quick-create-lab-powershell.md

File metadata and controls

107 lines (83 loc) · 4.14 KB
title description author ms.topic ms.date ms.custom
Azure Lab Services Quickstart - Create a lab using PowerShell
In this quickstart, you learn how to create an Azure Lab Services lab using PowerShell and the Az module.
RogerBestMSFT
quickstart
02/15/2022
template-quickstart

Quickstart: Create a lab using PowerShell and the Azure module

In this quickstart, you, as the educator, create a lab using PowerShell and the Azure modules. The lab will use the settings from a previously created lab plan. For detailed overview of Azure Lab Services, see An introduction to Azure Lab Services.

Prerequisites

Run Connect-AzAccount to sign in to Azure and verify an active subscription.

Create a lab

Before we can create a lab, we need the lab plan object. In the previous quickstart, we created a lab plan named ContosoLabPlan in a resource group named MyResourceGroup.

$plan = Get-AzLabServicesLabPlan `
    -Name "ContosoLabPlan" `
    -ResourceGroupName "MyResourceGroupName"

We also need to choose a base image for the lab VMs from the available images for the lab plan. Let's see what is available.

$plan | Get-AzLabServicesPlanImage | Where-Object { $_.EnabledState.ToString() -eq "enabled" }

We'll choose the Windows 11 image.

$image = $plan | Get-AzLabServicesPlanImage | Where-Object { $_.EnabledState.ToString() -eq "enabled" -and $_.DisplayName -eq "Windows 11 Pro (Gen2)" }

We're now ready to create a lab based of our lab plan with the Window 11 Pro image. The following command will create a lab using the lab plan created above.

# $plan and $image are from the Create LabPlan QuickStart.
$password = "<custom password>"

$lab = New-AzLabServicesLab -Name "ContosoLab" `
    -ResourceGroupName "MyResourceGroup" `
    -Location "westus" `
    -LabPlanId $plan.Id `
    -AdminUserPassword (ConvertTo-SecureString $password -AsPlainText -Force) `
    -AdminUserUsername "adminUser" `
    `
    -AutoShutdownProfileShutdownOnDisconnect Enabled `
    -AutoShutdownProfileDisconnectDelay $(New-Timespan) `
    -AutoShutdownProfileShutdownOnIdle "LowUsage" `
    -AutoShutdownProfileIdleDelay $(New-TimeSpan -Minutes 15) `
    -AutoShutdownProfileShutdownWhenNotConnected Disabled `
    -AutoShutdownProfileNoConnectDelay $(New-TimeSpan -Minutes 15) `
    `
    -ConnectionProfileClientRdpAccess Public `
    -ConnectionProfileClientSshAccess None `
    -ConnectionProfileWebRdpAccess None `
    -ConnectionProfileWebSshAccess None `
    -SecurityProfileOpenAccess Disabled `
    `
    -ImageReferenceOffer $image.Offer `
    -ImageReferencePublisher $image.Publisher `
    -ImageReferenceSku $image.Sku `
    -ImageReferenceVersion $image.Version `
    -SkuCapacity 1 `
    -SkuName "Classic_Fsv2_4_8GB_128_S_SSD" `
    `
    -Title "Contoso Lab" `
    -Description "The Contoso lab" `
    -AdditionalCapabilityInstallGpuDriver Disabled `
    -VirtualMachineProfileCreateOption "TemplateVM" `
    -VirtualMachineProfileUseSharedPassword Enabled

Clean up resources

If you're not going to continue to use this application, delete the plan and lab with the following steps:

$lab | Remove-AzLabServicesLab

More information

As an admin, you can learn more about Azure PowerShell module and Az.LabServices cmdlets.