How to Deploy a Virtual Machine in Azure with PowerShell

For this exercise, we will deploy a subnet called mySubnet with an address prefix of 10.0.0.0/24 on a 10.0.0.0/16 virtual network called myVnet.

Deploy the subnet first by running the following command in PowerShell and hitting Enter:

 

$mySubnet = New-AzureRmVirtualNetworkSubnetConfig -Name "mySubnet" -AddressPrefix 10.0.0.0/24

 

After running the command, you will be take back to the prompt.

With the subnet created, go ahead and deploy the virtual network by running the following command and hitting Enter:

 

$myVnet = New-AzureRmVirtualNetwork -Name "myVnet" -ResourceGroupName $myResourceGroup -Location $location -AddressPrefix 10.0.0.0/16 -Subnet $mySubnet

 

As was the case before, the above command is one long string.  If run successfully, you will simply be taken back to the prompt in PowerShell.

By now, you’ve deployed your resource group, storage account, and virtual network with a subnet attached to it.  It is now time to create a public IP address and network interface.  The network interface will allow your virtual machine to connect to your virtual network while your public IP address will allow you to RDP into your virtual machine once it has been deployed.

Create a public IP address and network interface

Before provisioning your network interface, you will want to provision your public IP address.  To do so, run the following command in PowerShell and hit Enter:

 

$myPublicIp = New-AzureRmPublicIpAddress -Name "myPublicIP" -ResourceGroupName $myResourceGroup -Location $location -AllocationMethod Dynamic

 

The command above is all one line and the result of it is a dynamic public IP address resource called myPublicIP.  You will assign this public IP while provision your virtual network interface (named myNIC) by running the command below and hitting Enter:

Click here to join the Understanding Azure Facebook group or here for the latest Azure practice questions, answers, explanations, and reference materials.

Thomas Mitchell

Tom is a 20+ year veteran of the IT industry and carries numerous Microsoft certifications, including the MCSE: Cloud Platform and Infrastructure certification. A Subject Matter Expert in Active Directory and Microsoft Exchange, Tom also possesses expert-level knowledge in several other IT disciplines, including Azure, Storage, and O365/Exchange Online. You can find Tom at his website, on LinkedIn, or on Facebook. Need to reach him by phone? Call 484-334-2790.