LabServices PowerShell Module

Published Apr 10 2020 02:28 PM 2,122 Views
Microsoft

Az.LabServices is a PowerShell module to simplify the management of Azure Lab services. It provides composable functions for IT, educator and student audiences.  For IT, there are functions to create, query, update and delete lab accounts, labs, VMs and images.  For students, there are newly added functions to help manage their virtual machines.

 

Getting Started

  1. Make sure you have a recent Azure PowerShell Module installed.
    Install-Module Az
  2. Copy Az.LabServices.psm1 anywhere on disk
    Invoke-WebRequest 'https://raw.githubusercontent.com/Azure/azure-devtestlab/master/samples/ClassroomLabs/Modules/Library/Az.LabServices.psm1' -OutFile 'Az.LabServices.psm1'​
  3. Import the Az.LabServices module.
    Import-Module .\Az.LabServices.psm1 -Force​
  4. Sign-in. 
    Login-AzAccount​
    For IT and educators, make sure your context is set to the subscription you are interested in by using Set-AzContext.  Student related functions are subscription agnostic, so don’t worry about the AzContext for those.

 

Examples for IT and Educators

For IT, there are functions to help manage lab accounts, labs, VMs and Images.  Let’s go over a few examples to see what we can do.

  • To see all the labs in a subscription:
    Get-AzLabAccount | Get-AzLab
  • To stop all running lab virtual machine for specific lab:

    Get-AzLabAccount | Get-AzLab -LabName ‘my-lab-name’ | Get-AzLabVm -Status Running
  • To print the email address of the students for a lab:

    Get-AzLabAccount | Get-AzLab -LabName ‘my-lab-name’ | Get-AzLabVm | Get-AzLabUser | ForEach-Object {Write-Host $_.properties.email}

More complex examples of usage are in the Az.LabServices scenarios.  For an example that creates a lab, see create an ethical hacking class example. 

 

Examples for Students

There are four functions in the Az.LabServices PowerShell module designed just for students.  You can start and stop your student virtual machines with Start-AzLabStudentVm and Stop-AzLabStudentVm.  Use Get-AzLabStudentVm to get a list of assigned virtual machines.  Lastly Get-AzLabStudentCurrentVm will get the information for the lab VM a student is currently logged into. Let’s go over some examples.

  • To start a lab virtual machine for a specific class:
    Get-AzLabStudentVm  | where name -eq ‘my-class-lab-name’ |Start-AzLabStudentVm
  • To stop all of your running lab virtual machines:
    Get-AzLabStudentVm  -Status Running | Stop-AzLabStudentVm
  • Want to stop the machine you’re currently logged onto and stop using quota?
    Get-AzLabStudentCurrentVm | Stop-AzLabStudentVm

We hope you find Az.LabServices PowerShell module helpful. Let us know if you have any feedback or questions for us in the comments section.

-Lab Services team

%3CLINGO-SUB%20id%3D%22lingo-sub-1297089%22%20slang%3D%22en-US%22%3ELabServices%20PowerShell%20Module%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1297089%22%20slang%3D%22en-US%22%3E%3CP%3EAz.LabServices%20is%20a%20PowerShell%20module%20to%20simplify%20the%20management%20of%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Fazure.microsoft.com%2Fen-in%2Fservices%2Flab-services%2F%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3EAzure%20Lab%20services%3C%2FA%3E.%20It%20provides%20composable%20functions%20for%20IT%2C%20educator%20and%20student%20audiences.%26nbsp%3B%20For%20IT%2C%20there%20are%20functions%20to%20create%2C%20query%2C%20update%20and%20delete%20lab%20accounts%2C%20labs%2C%20VMs%20and%20images.%26nbsp%3B%20For%20students%2C%20there%20are%20newly%20added%20functions%20to%20help%20manage%20their%20virtual%20machines.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3EGetting%20Started%3C%2FSTRONG%3E%3C%2FP%3E%0A%3COL%3E%0A%3CLI%3EMake%20sure%20you%20have%20a%20recent%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fpowershell%2Fazure%2Foverview%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%22%3EAzure%20PowerShell%20Module%3C%2FA%3E%26nbsp%3Binstalled.%3CPRE%20class%3D%22lia-code-sample%20language-markup%22%3E%3CCODE%3EInstall-Module%20Az%3C%2FCODE%3E%3C%2FPRE%3E%3C%2FLI%3E%0A%3CLI%3ECopy%20%3CA%20title%3D%22Az.LabServices%20module%22%20href%3D%22https%3A%2F%2Fraw.githubusercontent.com%2FAzure%2Fazure-devtestlab%2Fmaster%2Fsamples%2FClassroomLabs%2FModules%2FLibrary%2FAz.LabServices.psm1%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noreferrer%22%3EAz.LabServices.psm1%3C%2FA%3E%20anywhere%20on%20disk%3CPRE%20class%3D%22lia-code-sample%20language-markup%22%3E%3CCODE%3EInvoke-WebRequest%20'https%3A%2F%2Fraw.githubusercontent.com%2FAzure%2Fazure-devtestlab%2Fmaster%2Fsamples%2FClassroomLabs%2FModules%2FLibrary%2FAz.LabServices.psm1'%20-OutFile%20'Az.LabServices.psm1'%E2%80%8B%3C%2FCODE%3E%3C%2FPRE%3E%3C%2FLI%3E%0A%3CLI%3EImport%20the%20Az.LabServices%20module.%3CPRE%20class%3D%22lia-code-sample%20language-markup%22%3E%3CCODE%3EImport-Module%20.%5CAz.LabServices.psm1%20-Force%E2%80%8B%3C%2FCODE%3E%3C%2FPRE%3E%3C%2FLI%3E%0A%3CLI%3ESign-in.%26nbsp%3B%3CPRE%20class%3D%22lia-code-sample%20language-markup%22%3E%3CCODE%3ELogin-AzAccount%E2%80%8B%3C%2FCODE%3E%3C%2FPRE%3EFor%20IT%20and%20educators%2C%20make%20sure%20your%20context%20is%20set%20to%20the%20subscription%20you%20are%20interested%20in%20by%20using%20Set-AzContext.%26nbsp%3B%20Student%20related%20functions%20are%20subscription%20agnostic%2C%20so%20don%E2%80%99t%20worry%20about%20the%20AzContext%20for%20those.%3C%2FLI%3E%0A%3C%2FOL%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3EExamples%20for%20IT%20and%20Educators%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3EFor%20IT%2C%20there%20are%20functions%20to%20help%20manage%20lab%20accounts%2C%20labs%2C%20VMs%20and%20Images.%26nbsp%3B%20Let%E2%80%99s%20go%20over%20a%20few%20examples%20to%20see%20what%20we%20can%20do.%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3ETo%20see%20all%20the%20labs%20in%20a%20subscription%3A%3CPRE%20class%3D%22lia-code-sample%20language-markup%22%3E%3CCODE%3EGet-AzLabAccount%20%7C%20Get-AzLab%3C%2FCODE%3E%3C%2FPRE%3E%3C%2FLI%3E%0A%3CLI%3E%0A%3CP%3ETo%20stop%20all%20running%20lab%20virtual%20machine%20for%20specific%20lab%3A%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-markup%22%3E%3CCODE%3EGet-AzLabAccount%20%7C%20Get-AzLab%20-LabName%20%E2%80%98my-lab-name%E2%80%99%20%7C%20Get-AzLabVm%20-Status%20Running%3C%2FCODE%3E%3C%2FPRE%3E%3C%2FLI%3E%0A%3CLI%3E%0A%3CP%3ETo%20print%20the%20email%20address%20of%20the%20students%20for%20a%20lab%3A%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-powershell%22%3E%3CCODE%3EGet-AzLabAccount%20%7C%20Get-AzLab%20-LabName%20%E2%80%98my-lab-name%E2%80%99%20%7C%20Get-AzLabVm%20%7C%20Get-AzLabUser%20%7C%20ForEach-Object%20%7BWrite-Host%20%24_.properties.email%7D%3C%2FCODE%3E%3C%2FPRE%3E%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3EMore%20complex%20examples%20of%20usage%20are%20in%20the%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2FAzure%2Fazure-devtestlab%2Fblob%2Fmaster%2Fsamples%2FClassroomLabs%2FModules%2FLibrary%2FScenarios%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3EAz.LabServices%20scenarios%3C%2FA%3E.%26nbsp%3B%20For%20an%20example%20that%20creates%20a%20lab%2C%20see%20%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2FAzure%2Fazure-devtestlab%2Ftree%2Fmaster%2Fsamples%2FClassroomLabs%2FScripts%2FEthicalHacking%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3Ecreate%20an%20ethical%20hacking%20class%3C%2FA%3E%20example.%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3EExamples%20for%20Students%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3EThere%20are%20four%20functions%20in%20the%20Az.LabServices%20PowerShell%20module%20designed%20just%20for%20students.%26nbsp%3B%20You%20can%20start%20and%20stop%20your%20student%20virtual%20machines%20with%20Start-AzLabStudentVm%20and%20Stop-AzLabStudentVm.%26nbsp%3B%20Use%20Get-AzLabStudentVm%20to%20get%20a%20list%20of%20assigned%20virtual%20machines.%26nbsp%3B%20Lastly%20Get-AzLabStudentCurrentVm%20will%20get%20the%20information%20for%20the%20lab%20VM%20a%20student%20is%20currently%20logged%20into.%20Let%E2%80%99s%20go%20over%20some%20examples.%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3ETo%20start%20a%20lab%20virtual%20machine%20for%20a%20specific%20class%3A%3CPRE%20class%3D%22lia-code-sample%20language-markup%22%3E%3CCODE%3EGet-AzLabStudentVm%20%20%7C%20where%20name%20-eq%20%E2%80%98my-class-lab-name%E2%80%99%20%7CStart-AzLabStudentVm%3C%2FCODE%3E%3C%2FPRE%3E%3C%2FLI%3E%0A%3CLI%3ETo%20stop%20all%20of%20your%20running%20lab%20virtual%20machines%3A%3CPRE%20class%3D%22lia-code-sample%20language-markup%22%3E%3CCODE%3EGet-AzLabStudentVm%20%20-Status%20Running%20%7C%20Stop-AzLabStudentVm%3C%2FCODE%3E%3C%2FPRE%3E%3C%2FLI%3E%0A%3CLI%3EWant%20to%20stop%20the%20machine%20you%E2%80%99re%20currently%20logged%20onto%20and%20stop%20using%20quota%3F%3CPRE%20class%3D%22lia-code-sample%20language-markup%22%3E%3CCODE%3EGet-AzLabStudentCurrentVm%20%7C%20Stop-AzLabStudentVm%3C%2FCODE%3E%3C%2FPRE%3E%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3EWe%20hope%20you%20find%20Az.LabServices%20PowerShell%20module%20helpful.%20Let%20us%20know%20if%20you%20have%20any%20feedback%20or%20questions%20for%20us%20in%20the%20comments%20section.%3C%2FP%3E%0A%3CP%3E-Lab%20Services%20team%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-TEASER%20id%3D%22lingo-teaser-1297089%22%20slang%3D%22en-US%22%3E%3CP%3EAz.LabServices%20is%20a%20PowerShell%20module%20that%20can%20simplify%20the%20management%20of%20%3CA%20href%3D%22https%3A%2F%2Fazure.microsoft.com%2Fen-in%2Fservices%2Flab-services%2F%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%22%3EAzure%20Lab%20Services%3C%2FA%3E.%26nbsp%3B%26nbsp%3BIt%20provides%20composable%20functions%20for%20IT%2C%20educator%20and%20student%20audiences.%26nbsp%3B%20For%20IT%20there%20are%20functions%20to%20create%2C%20query%2C%20update%20and%20delete%20lab%20accounts%2C%20labs%2C%20VMs%20and%20Images.%26nbsp%3B%20For%20students%2C%20there%20are%20newly%20added%20functions%20to%20help%20manage%20their%20virtual%20machines.%3C%2FP%3E%3C%2FLINGO-TEASER%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1297089%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3ELab%20Services%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
Version history
Last update:
‎Apr 10 2020 02:28 PM
Updated by: