How to Deploy a Virtual Machine in Azure with PowerShell

For this exercise, note the location westus as your chosen location and let’s call the resource group myAzureResourceGroup.

Now that you’ve settled on a location and name for your resource group, type the following three commands in PowerShell, hitting Enter after each one:

 

$location = "westus"

$myResourceGroup = "myAzureResourceGroup"

New-AzureRmResourceGroup -Name $myResourceGroup -Location $location

At this point, your Resource Group named myAzureResourceGroup has been provisioned in the West US location.  With your resource group deployed, it’s time to create a storage account to hold your storage for your VM.

Create Storage Account

Before creating your storage account, you have to settle on a name that is unique across the entire Azure landscape.  The name of your storage account must be between 3 and 24 characters and must consist only of lower case letters and numbers.

For this exercise, we will call the storage account myazurestorageacct1973.

To check the availability of the name, type the following two commands in PowerShell, hitting Enter after each one:

 

$myStorageAccountName = " myazurestorageacct1973"

Get-AzureRmStorageAccountNameAvailability $myStorageAccountName

 

If the second command returns True, the proposed name is unique within Azure and can be used.

To deploy the storage account, type the following command and hit Enter:

 

$myStorageAccount = New-AzureRmStorageAccount -ResourceGroupName $myResourceGroup -Name $myStorageAccountName -SkuName "Standard_LRS" -Kind "Storage" -Location $location

 

NOTE: The above command is one long line.

If everything goes as it should, you should just be taken back to the prompt in PowerShell:

Create a virtual network

Now that the resource group and storage account have been deployed, go ahead and create the virtual network that your eventual virtual machine will live on.  To do this, you will have to deploy two resources: subnet and virtual network.

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.