How can I find all DevTest Labs environments via powershell?

Joel Stephens 0 Reputation points

I am looking for a way to automatically delete a DevTest Lab environment after a period of time. The previously supplied solution of applying an auto-delete policy does not seem to exist anymore in the current version of the DevTest Labs portal.

I am looking in to using powershell to delete the lab environment but I am unable to figure out how to refer to the environment resource to delete it. I can get the lab by using the powershell command "get-azresource -ResourceType Microsoft.DevTestLab/labs -Name labname". How can I find all lab environments that would appear under My Environments for each user?

Azure DevTest Labs
Azure DevTest Labs
An Azure service that is used for provisioning development and test environments.
250 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. shiva patpi 12,961 Reputation points Microsoft Employee

    @Joel Stephens ,

    You can use the below command to retrieve the environments under a specific lab:

    Get-AzureRmResource -ResourceGroupName devlab1 -ResourceType 'Microsoft.DevTestLab/labs/users/environments' -ResourceName "devlab1/@all" -ApiVersion '2016-05-15'

    Executed above command below is the sample output:

    User's image

    I have extracted that piece of code from below modules:- (It has got good amount of code , you just need to tweak it based upon your requirements)


    User's image



    0 comments No comments