Set expiration date for VMs in Azure DevTest Labs


In scenarios such as training, demos and trials, you may want to create virtual machines and delete them automatically after a fixed duration so that you don’t incur unnecessary costs. We recently announced a feature which allows you to do just that - set an expiration date for a lab VM.

This feature is currently only available using our APIs which you can use through Azure resource manager (ARM) template, Azure PowerShell SDK and Azure CLI.

You can create a lab VM with an expiration date using an ARM template by specifying the expirationDate property for the VM. You can check out a sample Resource Manager template in our public GitHub repository. You can also modify any of the existing sample Resource Manager templates for the VM creation (name starting with 101-dtl-create-vm) by adding the expirationDate property as follows.

"resources": [

{

"apiVersion": "2016-05-15",

"type": "Microsoft.DevTestLab/labs/virtualMachines",

"name": "[variables('resourceName')]",

"location": "[resourceGroup().location]",

"properties": {

"customImageId": "[parameters('existingCustomImageId')]",

"size": "[parameters('newVMSize')]",

"isAuthenticationWithSshKey": false,

"userName": "[parameters('userName')]",

"sshKey": "",

"password": "[parameters('password')]",

"labVirtualNetworkId": "[variables('labVirtualNetworkId')]",

"labSubnetName": "[variables('labSubnetName')]",

"expirationDate": "[parameters('expirationDate')]"

}

}]

You can set an expiration date for an already existing lab VM or all the VMs in the lab using Azure PowerShell cmdlets. Sharing a sample script that you can use.

# Values to change

$subscriptionId = '<Enter the subscription Id that contains lab>'

$labResourceGroup = '<Enter the lab resource group>'

$labName = '<Enter the lab name>'

$VmName = '<Enter the VmName>'

$expirationDate = '<Enter the expiration date e.g. 2016-09-16>'

# Log into your Azure account

Login-AzureRmAccount

Select-AzureRmSubscription -SubscriptionId $subscriptionId

$VmResourceId = "subscriptions/$subscriptionId/resourcegroups/$labResourceGroup/providers/microsoft.devtestlab/labs/$labName/virtualmachines/$VmName"

$vm = Get-AzureRmResource -ResourceId $VmResourceId -ExpandProperties

# Get all the Vm properties

$VmProperties = $vm.Properties

# Set the expirationDate property

$VmProperties | Add-Member -MemberType NoteProperty -Name expirationDate -Value $expirationDate

Set-AzureRmResource -ResourceId $VmResourceId -Properties $properties -Force

 

Please try the feature and let us know how we can make it better by sharing your ideas and suggestions at the DevTest Labs feedback forum.

If you run into any problems with the feature or have any questions, we are always ready to help you at our MSDN forum.

 

Comments (2)

  1. Ravi says:

    @Devtestlabs team, please enable RSS feed for you blog, how are we supposed to keep up with all the new updates?

    1. Xiaoying Guo says:

      @Ravi, thanks for your suggestion. I’ve added the RSS feed link at the homepage. You can also subscribe it through https://blogs.msdn.microsoft.com/devtestlab/feed/.

Skip to main content