Upload a Windows 10 VM to Azure Resource Manager

I needed to upload and create a Windows 10 image to an Azure tenant that didn't have one available. Most of them don't unless they're given as part of an MSDN subscription. This is the How-To.

The steps:

  1. Create a base image with the features, software, patches and whatever else you need

  2. Mark it as image

  3. Upload it to Azure - ARM mode

  4. Create the image from the base

Here's the original desktop I created on my Azure tenant :

[caption id="" align="aligncenter" width="2556"]

Hello Windows 10, Windows 10 N actually. Same Windows but with no Media Related Technologies[/caption]

[caption id="" align="aligncenter" width="1730"]

I properly called it Windows10Base[/caption]

[caption id="" align="aligncenter" width="2130"]

After patching and adding all the required components. The next step is to run sysprep[/caption]

[caption id="" align="aligncenter" width="582"]

It normally takes 10 to 15 minutes to finish. Once it's done, the VM will be deleted form the Tenant, the VM, not the disk.[/caption]

[caption id="" align="alignnone" width="1822"]

Here's the sysprep-ed VHD to be used as an image[/caption]

Note: You have to shutdown the VM and mark it as image after the sysprep, if this is not done, the VM will not be able to be used as an image to create other VMs

Stop-AzureRmVM -ResourceGroupName '<Your Resource Group here>' -Name '<Vm Name>'
Set-AzureRmVM -ResourceGroupName '<Your Resource Group Name' -Name ''<VM Name>"  -Generalized

Next, was to download the .vHD. Remember this was created in one subscription and uploaded to another.

[caption id="" align="aligncenter" width="2638"]

I used the Azure Storage Explorer in a Windows Box[/caption]

Now I had the .vHD file locally, it can be uploaded to the corresponding storage account in the target subscription.

The quick steps:

Login-AzureRmAccount - It will challenge you to provide the username/password set
Select-AzureRmSubscription -SubscriptionId "xxxx-xxxx-xxxx-xxxx" - In case you have access to more than one subscription

I created a container inside a storage account for this .vHD https://[whatevernamesuitsyou].blob.core.windows.net/vhd

Time to upload the .vHD to the target Subscription

Add-AzureRmVhd -ResourceGroupName [YourResourceGroupName] `
-Destination "https://[whatevernamesuitsyou].blob.core.windows.net/vhd/windows10basehd.vhd" `
-LocalFilePath .\Windows10Base2016326141340.vhd

It will look like this:

[caption id="" align="aligncenter" width="2550"]

It took 1 1/2 hours to upload[/caption]

The .vHD is up, now what?

Time to create the Virtual Machine

#By Roberto Lopez aka @soyroberto
#modified from
#April 2016
# You can copy/paste this code and adjust it, as long as your VHD is up and generalised
#You have to fill all things in ""
$rgname = ""  #change it to your corresponding RG name
$storageAccName = "" #change it to your storage account name
$location = "" # put your Azure region here
$vnet = "" #adjust your Vnet Name here

#change names below for uniqueness
As an improve you could modify the variables below to make them automatic.
$nicname = "" #name of the Card for the VM
$vmname = "" #Name of VM. This is the name you see in the Azure portal
$computerName = "" #Computer name of the VM/The one you see in Windows
$osDiskName = "" #Name of the HDD
$pipname ="" #IP - Name of the IPcard
$urlOfUploadedImageVhd = "" # The base Image VHD uploaded, syspreped and marked as an OS

#changes finished , sort of
$pip = New-AzureRmPublicIpAddress -Name $pipname -ResourceGroupName $rgname -Location $location -AllocationMethod Dynamic
$vnetname = Get-AzureRmVirtualNetwork -Name $vnet -ResourceGroupName $rgname
$subnetid = (Get-AzureRmVirtualNetworkSubnetConfig -Name 'default' -VirtualNetwork $vnetname).id #the name of the Vnet the VM will be created
#changes finished
$nic = New-AzureRmNetworkInterface -Name $nicname -ResourceGroupName $rgName -Location $location -PublicIpAddressId $pip.Id -SubnetId $subnetid # -subnetid $vnet.Subnets[0].Id
#Get the storage account where the uploaded image is stored
$storageAcc = Get-AzureRmStorageAccount -ResourceGroupName $rgName -AccountName $storageAccName
#Set the VM name and size
#Use "Get-Help New-AzureRmVMConfig" to know the available options for -VMsize
$vmConfig = New-AzureRmVMConfig -VMName $vmName -VMSize "Standard_DS2_v2"
#Set the Windows operating system configuration and add the NIC
orig $vm = Set-AzureRmVMOperatingSystem -VM $vmConfig -Windows -ComputerName $computerName -Credential $cred -ProvisionVMAgent -EnableAutoUpdate
$vm = Set-AzureRmVMOperatingSystem -VM $vmConfig -Windows -ComputerName $computerName  -ProvisionVMAgent -EnableAutoUpdate
$vm = Add-AzureRmVMNetworkInterface -VM $vm -Id $nic.Id
#Create the OS disk URI
$osDiskUri = '{0}vhds/{1}{2}.vhd' -f $storageAcc.PrimaryEndpoints.Blob.ToString(), $vmName.ToLower(), $osDiskName
#Configure the OS disk to be created from image (-CreateOption fromImage) and give the URL of the uploaded image VHD for the -SourceImageUri parameter
#You can find this URL in the result of the Add-AzureRmVhd cmdlet above
$vm = Set-AzureRmVMOSDisk -VM $vm -Name $osDiskName -VhdUri $osDiskUri -CreateOption fromImage -SourceImageUri $urlOfUploadedImageVhd -Windows
#Create the new VM
New-AzureRmVM -ResourceGroupName $rgName -Location $location -VM $vm
End of Script

And that's it

You will have a Windows 10 VM created in Azure ARM