0

I'm tasked with automating the creation of Azure VM's, and naturally I do a number of more or less broken iterations of trying to deploy a VM image. As part of this, I automatically allocate serial hostnames, but there's a strange reason it's not working:

The code in the link above works very well, but the contents of my ResourceGroup is not as expected. Every time I deploy (successfully or not), a new entry is created in whatever list is returned by Get-AzureRmResourceGroupDeployment; however, in the Azure web interface I can only see a few of these entries. If, for instance, I omit a parameter for the JSON file, Azure cannot even begin to deploy something -- but the hostname is somehow reserved anyway.

Where is this list? How can I clean up after broken deployments?

Currently, Get-AzureRmResourceGroupDeployment returns:

azure-w10-tfs13
azure-w10-tfs12
azure-w10-tfs11
azure-w10-tfs10
azure-w10-tfs09
azure-w10-tfs08
azure-w10-tfs07
azure-w10-tfs06
azure-w10-tfs05
azure-w10-tfs02
azure-w7-tfs01
azure-w10-tfs19
azure-w10-tfs1

although the web interface only lists:

azure-w10-tfs12  
azure-w10-tfs13  
azure-w10-tfs09
azure-w10-tfs05
azure-w10-tfs02

Solved using the code $siblings = (Get-AzureRmResource).Name | Where-Object{$_ -match "^$hostname\d+$"}

(PS. If you have tips for better tags, please feel free to edit this question!)

Community
  • 1
  • 1
KlaymenDK
  • 714
  • 9
  • 31

1 Answers1

1

If you create a VM in Azure Resource Management mode, it will have a deployment attached to it. In fact if you create any resource at all, it will have a resource deployment attached.

If you delete the resource you will still have the deployment record there, because you still deployed it at some stage. Consider deployments as part of the audit trail of what has happened within the account.

You can delete deployment records with Remove-AzureRmResourceGroupDeployment but there is very little point, since deployments have no bearing upon the operation of Azure. There is no cost associated they are just historical records.

Querying deployments with Get-AzureRmResourceGroupDeployment will yield you the following fields.

DeploymentName 
Mode              
Outputs           
OutputsString     
Parameters        
ParametersString  
ProvisioningState 
ResourceGroupName 
TemplateLink      
TemplateLinkString
Timestamp      

So you can know whether the deployment was successful via ProvisioningState know the templates you used with TemplateLink and TemplateLinkString and check the outputs of the deployment etc. This can be useful to figure out what template worked and what didn't.

If you want to see actual resources, that you are potentially being charged for, you can use Get-AzureRmResource

If you just want to retrieve a list of the names of VMs that exist within an Azure subscription, you can use

(Get-AzureRmVM).Name 
Michael B
  • 11,887
  • 6
  • 38
  • 74
  • Aha, thank you. I will use `Get-AzureRmResource` instead of `Get-AzureRmResourceGroupDeployment` to determine the hostnames in actual use. – KlaymenDK Feb 04 '16 at 10:33