Move Azure VM from Premium to Standard Storage

Took me awhile to work out the specifics but this works.  You can have the exact VM running on a Premium storage account up and running again on a Standard storage account in only a few minutes. Note: this is for ARM, not classic.

  • Stop the VM so it says “Stopped (deallocated)”, not just “Stopped”. Shutting it down from RDP isn’t enough. Do this via the portal, right-click, STOP.
  • Copy its VHD from the Premium storage account to a Standard storage account:
$sourceBlobUri = "https://yourpremiumstorage.blob.core.windows.net/vhds/yourvhdname.vhd"
$sourceContext = New-AzureStorageContext –StorageAccountName "yourpremiumstorage" -StorageAccountKey "AsFRVDK3wH3mBfagiym6OdkC"
$destinationContext = New-AzureStorageContext –StorageAccountName "yourstandardstorage" -StorageAccountKey "JeQdlvNXZ+Vq6"
Start-AzureStorageBlobCopy -srcUri $sourceBlobUri -SrcContext $sourceContext -DestContainer "vhds" -DestBlob "your-new-vhd-name.vhd" -DestContext $destinationContext

Next, create a new VM using the copied VHD. This came from here, then I modified to use an existing VNet rather than creating one.

## Global
$rgName = "resource-group-name"
$location = "westus"

## Storage
$storageName = "yourstandardstorage"
$osDiskUri = "https://yourstandardstorage.blob.core.windows.net/vhds/yourvhdname.vhd"

## Network
$vnetName = "your-net"
$subnetName = "your-subnet"
$nicname = "nic-name"
$ipname = "ip-name"

## Compute
$vmName = "vm-name"
$vmSize = "Standard_A2"
$osDiskName = $vmName + "osDisk"

#Setup Network
$vnet = Get-AzureRmVirtualNetwork -Name $vnetName -ResourceGroupName $rgName
$subnet = Get-AzureRmVirtualNetworkSubnetConfig -Name $subnetName -VirtualNetwork $vnet

$pip = New-AzureRmPublicIpAddress -Name $ipname -ResourceGroupName $rgName -Location $location -AllocationMethod Dynamic
$nic = New-AzureRmNetworkInterface -Name $nicname -ResourceGroupName $rgName -Location $location -SubnetId $subnet.Id -PublicIpAddressId $pip.Id

## Setup local VM object
$vm = New-AzureRmVMConfig -VMName $vmName -VMSize $vmSize
$vm = Add-AzureRmVMNetworkInterface -VM $vm -Id $nic.Id
$vm = Set-AzureRmVMOSDisk -VM $vm -Name $osDiskName -VhdUri $osDiskUri -CreateOption attach -Windows

## Create the VM in Azure
New-AzureRmVM -ResourceGroupName $rgName -Location $location -VM $vm -Verbose -Debug

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s