Wednesday 29 October 2014

Export / Import Lab Virtual Machines

  1. De-provision the lab. Use the Stop-AzureVM and Export-AzureVM cmdlets in the PowerShell snippet below to shutdown and export lab VMs when they are not being used.  
     
    # Specify the Name of the VM to Export
     
    $myVM = "XXXlabad01" 
     
    # Stop the VM prior to exporting it
     
    Stop-AzureVM -ServiceName $myVM -Name $myVM 
     
    # Set the Export folder path for the VM configuration file.  Make sure this folder exists!

     
    $ExportPath = "C:\ExportVMs\ExportAzureVM-$myVM.xml" 
     
    # Export the VM to a file
     
    Export-AzureVM -ServiceName $myVM -name $myVM -Path $ExportPath  
     
    # After you've confirmed that the Export file exists, delete the VM
     
    Remove-AzureVM -ServiceName $myVM -name $myVM

     
  2. Re-provision the lab. Use the Import-AzureVM and Start-AzureVM cmdlets in the PowerShell snippet below to import and start lab VMs when needed again.
     
    # Specify the Name of the VM to Import

    $myVM = “XXXlabad01" 

    # Specify the Name of the Virtual Network on which to Import the VM

    $myVNet = "XXXlabnet01"

    # Specify the Import Path of the VM’s exported configuration file.
     
    $ImportPath = "C:\ExportVMs\ExportAzureVM-$myVM.xml"

    # Specify the Windows Azure Storage Account to be used.

    $myStorageAccount = "XXXlabstor01"

    Get-AzureSubscription | Set-AzureSubscription -CurrentStorageAccount $myStorageAccount 
     
    # Import the VM to Windows Azure
     
    Import-AzureVM -Path $ImportPath | New-AzureVM -ServiceName $myVM -VNetName $myVNet 
     
    # Start the VM  
    Start-AzureVM -ServiceName $myVM -name $myVM

No comments:

Post a Comment