Creating a VM to Azure in PowerShell from a VHD existing [Exclusive Guide]
in previous article, I talked about how send a VHD personalized from your local station to Azure. Today we will see how from a VHD House we can create a virtual machine and all the necessary components for its operation on the Microsoft cloud.
In my example, the objective will be to provision a Windows 10 type VM directly in Azure. Indeed, by default (et pour l’instant en tout cas – 25/10/2016) , it is still impossible to provision a VM Windows 10 in Windows Azure (unless your subscribe is obtained via an MSDN Visual Studio Developer account). If you have tested, you will maybe observed the following messages:
Exclusively available for MSDN subscription…
So I created a VHD on which I have installed Windows 10 and I transferred it in a container on my Storage Account . For more information about how to transfer a VHD to Auzre, I invite you to read the article .
We will therefore now use this VHD and tie it to my existing infrastructure. To retrieve the full path to your VHD, we need for the future. 😉
of course, when I say existing infrastructure, this means that you must already have the following components (que nous aurons besoin de mentionner dans la CmdLet qui va nous permettra de créer notre virtual machine) :
- Resource Group
- Virtual Network
- rental (westeurope, northeurope, etc.)-this is the code name for the different centres Azure worldwide. You can find the list in according to this URL .
- (possibly) “Public IP (si votre VM doit disposer d’une adresse IP publique)
- (possibly) Availability Set [19459010-](si vous souhaitez rattacher cette machine virtuelle à un Availability Set déjà existant)
once you are ready we will run the following CmdLet:
#Login - AzureRmAccount (you must be logged on Azure) #Select-AzureRmSubscription - SubscribtionId"xxx-xxx-xxx"(you have already selected the subscription in which you work) $resourceGroupName ="ctxtgi12"$destinationVhd ="https://xxxxxxxx.blob.core.windows.net/vhds/template_Windows10_tgi.vhd"$virtualNetworkName =" VirtualNetwork"$locationName ="westeurope"$virtualNetwork = Get-AzureRmVirtualNetwork - ResourceGroupName $resourceGroupName-$virtualNetworkName $publicIp Name = New-AzureRmPublicIpAddress - Name"Win10-PIP"- ResourceGroupName $ResourceGroupName - rental $locationName - AllocationMethod Static $networkInterface = New-AzureRmNetworkInterface - ResourceGroupName $resourceGroupName - Name"Win10-NIC"- $locationName - SubnetId rental $virtualNetwork.Subnets . ID - PublicIpAddressId $publicIp.Id $availabilityset = (Get-AzureRmAvailabilitySet - ResourceGroupName $resourceGroupName) . $vmConfig ID = New-AzureRmVMConfig-"MyVMWindows10" - VMSize "Standard_DS1" VMName # - AvailabilitySetID $availabilityset $vmConfig = Set-AzureRmVMOSDisk - VM $vmConfig - Name "MyVMWindows10" - VhdUri $destinationVhd - CreateOption Attach - Windows $vmConfig = Add-AzureRmVMNetworkInterface - VM $vmConfig - Id $networkInterface.Id New-AzureRmVM - VM $vmConfig - $locationName - ResourceGroupName $resourceGroupName rental
A course tailor your case! 🙂
If you look a little more close the few lines above, we can note the following points:
- my VM is automatically added in my VirtualNetwork and will therefore have an IP in my Subnet . In the present case and in view of the choice of configuration of my VirtualNetwork , my VM will be given a NIC Win10-NIC with a static type IP.
- I also automatically assigns a IP address public Win10-PIP named .
- My VM will be called MyVMWindows10 and will be fine in the area West Europe .
- You can also integrate it automatically at a Set Availability (attention à accorder votre choix de Size VM) . In my example, I created a VM of type Standard_DS1 .
- And finally, in the penultimate line we use the parameter attach to attach our VHD to our new virtual machine and they are told that it will be a VM for Windows type .
After a few moments, you will notice on the portal Azure that items have been created and that our virtual machine has also been automatically started:
the virtual machine has been generated in accordance with our needs (ip interne dans le virtual network, ip publique, sizing, azure location, etc.) . to check that everything is in order, you just so more to sign in to RDP! 🙂
a big thank you to Leon which this article allowed me to move forward on this point: https://blogs.infosupport.com/creating-a-vm-in-azure-based-on-an-uploaded-vhd/ . 🙂