LabServices PowerShell Module

This post has been republished via RSS; it originally appeared at: New blog articles in Microsoft Tech Community.

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 diskInvoke-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

Leave a Reply

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

*

This site uses Akismet to reduce spam. Learn how your comment data is processed.