Rick Gittins
Rick Gittins

Reputation: 1138

Creating Linux Virtual Machine in Azure from Image in Powershell

I want to be able to create a new Azure Virtual Machine using Powershell with a custom image. This custom image is in Azure Storage Account X and the new Virtual Machine will be created using Azure Storage Account Y. When I run these commands to create the new Virtual Machine:

Set-AzureSubscription -CurrentStorageAccount $StorageAccount -SubscriptionName $SubscriptionName

New-AzureVMConfig -Name $MachineName -InstanceSize $InstanceSize -ImageName $Image | 
    Add-AzureProvisioningConfig -Linux -LinuxUser $LinuxUser -Password $AdminPassword | 
    Set-AzureSubnet $subNet | 
    New-AzureVM -ServiceName $MachineName -VNetName $VNet -ErrorVariable errs

where $Image is the custom image in Storage Account X and CurrentStorageAccount set to Y for the Subscription, I get the following error:

The disk's VHD must be in the same account as the VHD of the source image 

If the custom image is in Storage Account Y the commands to create the new Virtual Machine work correctly.

Can an Azure Virtual Machine be created when the image is in a different Storage Account?

Upvotes: 0

Views: 2043

Answers (1)

Rick Rainey
Rick Rainey

Reputation: 11246

Apparently not. However, you could copy the image from storage account X to storage account Y before you create the new VM. It would only add a few more lines to your script.

Here is an example:

http://michaelwasham.com/windows-azure-powershell-reference-guide/copying-vhds-blobs-between-storage-accounts/

Upvotes: 2

Related Questions