Search code examples
azureazure-storageazure-virtual-machineazure-powershellazure-virtual-network

PowerShell Azure IaaS export of Virtual Machine, Virtual Network and Storage for DR


Does anyone know a way, and/or have sample code, to retrieve the following information from an Azure IaaS Virtual Machine implementation?

  1. The associated Virtual Network, by name - NOT the subnet; I can get this already and, as it's not unique for all Virtual Network's in a subscription, can't be used.
  2. The storage account for the VM's attached disks

For additional context to the question, we're attempting to generate XML for DR purposes which will allow us to rebuild our IaaS implementation on a secondary data centre in the event of primary failure. We've managed to retrieve most, if not all, the information we require, but can't find a way to get the VNet(s) from the VM (or vice-versa) or the storage account(s)/container(s) for the VM's disks.


Solution

  • I will answer the second part of your question. That's pretty easy using powershell. suppose vm name as "testvm" and service name as "testservice". Powershell to get the storage account name-

     $disk = Get-AzureVM -ServiceName "testservice" –Name "testvm" | Get-AzureOSDisk
     $mediaLink = $disk.MediaLink
     $storageAccountName = $mediaLink.Host.Split('.')[0]
     $storageAccountName 
    

    Hope this answers your question.