1

In the classic portal/ASM I could use some simple PowerShell cmdlets to create a VM using my own vhd. Once the variables were set the flow was pretty much Add-AzureVhd > Add-AzureDisk > New-AzureVm.

For the life of me I cannot find any documentation on creating an ARM VM using PowerShell with my own vhd.

Can anyone point me in the right direction?

Edit: Here is the code I am using.

$rgName = "somerg"
$location = "centralus"
$storageName = "somestorage"
$storageType = "Standard_LRS"

$nicname = "client1nic"
$subnet1Name = "Subnet-1"
$vnetName = "somevnet"
$vnetAddressPrefix = "10.0.0.0/16"
$vnetSubnetAddressPrefix = "10.0.0.0/24"

$vmName = "Client1"
$vmSize = "Standard_A2"
$osDiskName = $vmName + "osDisk"

$pip = New-AzureRmPublicIpAddress -Name $nicname -ResourceGroupName $rgName                 -Location $location -AllocationMethod Dynamic
$nic = New-AzureRmNetworkInterface -Name $nicname -ResourceGroupName $rgName    -Location $location -SubnetId $vnet.Subnets[0].Id -PublicIpAddressId $pip.Id
$vm = New-AzureRmVMConfig -VMName $vmName -VMSize $vmSize$vm = Add-  AzureRmVMNetworkInterface -VM $vm -Id $nic.Id
$osDiskUri = "https://somestorage.blob.core.windows.net/vhds/Client1.vhd"
$vm = Set-AzureRmVMOSDisk -VM $vm -Name $osDiskName -VhdUri $osDiskUri -  CreateOption attach -Windows

New-AzureRmVM -ResourceGroupName $rgName -Location $location -VM $vm -  Verbose -Debug
Adam S.
  • 13
  • 5

1 Answers1

1

Set-AzureRmVMOSDisk has three options when creating an OS disk using the -CreateOptions The first is fromImage which creates an a machine from a prior image.

There is then attach which attaches a preexisting disk, which would be the option you require.

There is also empty but I've not found the use case for that as yet!

Anyway, this should do what you need.

Set-AzureRmVMOSDisk -VM $vm -Name "test" -VhdUri $uri -CreateOption attach -Windows 

Wrapped into the rest of a VM Create script

Michael B
  • 11,887
  • 6
  • 38
  • 74
  • I get a new error: ErrorCode: DiskBlobNotFound. The disk is most definitely there. I sysprepped the image in Hyper-V before uploading to the blob. – Adam S. Feb 05 '16 at 02:04
  • Thanks Michael B. That last line of code seemed to work. I failed to export the vhd after I ran sysprep from Hyper-V. Once I did that and re-upload to the blob storage I was able to create the Vm. – Adam S. Feb 05 '16 at 03:40