5

I have a VHD in Azure storage. That VHD is configured as an OS disk through a command like the following:

Add-AzureDisk -DiskName $newCode -MediaLocation "http://$script:accountName.blob.core.windows.net/$newCode/$sourceVhdName.vhd" `
    -Label $newCode -OS "Windows"

I would like to create a new VM pointing at that disk. From what I can tell if I was doing this with an image I would do something like:

New-AzureVMConfig -Name $newCode -InstanceSize $instanceSize `
    -MediaLocation "http://$script:accountName.blob.core.windows.net/$newCode/$sourceVhdName.vhd" -ImageName $newCode  `
    | Add-AzureProvisioningConfig -Windows -Password $adminPassword `
    | New-AzureVM -ServiceName $newCode 

However this is wrong for me because I don't have an image - I have a configured VHD that is not sysprepped and can't be.

How can I create the VM in PowerShell to point at the existing disk like I can through the portal?

MikeBaz - MSFT
  • 1,253
  • 3
  • 15
  • 37
  • I am trying to find an answer to this as well. I see that Add-AzureDisk has parameters for -DiskName and -DiskLabel, but I have tried both and not had success. I have a single disk that I can use when creating a VM from the web manager, but haven't been able to automate this with PowerShell... – aSkywalker Dec 11 '12 at 04:58

1 Answers1

3

So it appears from http://michaelwasham.com/2013/01/04/migrate-a-virtual-machine-to-windows-azure-with-powershell/ that the recent cmdlet update closed this gap - there's a script there that includes the upload and the VM creation from the upload.

MikeBaz - MSFT
  • 1,253
  • 3
  • 15
  • 37
  • that link is now out of date - but in the documentation there's a script around this specific task for both managed and unmanaged disks: https://docs.microsoft.com/en-us/azure/virtual-machines/scripts/virtual-machines-windows-powershell-sample-create-vm-from-managed-os-disks and https://docs.microsoft.com/en-us/azure/virtual-machines/scripts/virtual-machines-windows-powershell-upload-generalized-script – MikeBaz - MSFT Oct 08 '19 at 16:16