How to Deploy a Virtual Machine in Azure with PowerShell

Introduction

I’m a GUI guy.  When offered the choice between using a GUI to perform a task and using PowerShell, I will almost always choose the GUI.  However, that does not mean I won’t or can’t use PowerShell.  In fact, any Microsoft engineer worth anything should be familiar with using PowerShell.  As such, I’m going to explain to you in this article how to use PowerShell to configure and deploy several Azure resources, including a Resource Group, a Storage Account, a Virtual Network, a Subnet, a Public IP address, a Network Interface, and last, but not least, a Virtual Machine.

Install Azure PowerShell

Before doing anything in Azure with PowerShell, you are going to have to install Azure PowerShell.  To do so, visit this link and click on Windows Install under the PowerShell section.

Connect to Azure with PowerShell

Once you’ve installed Azure PowerShell, go ahead and launch PowerShell from your workstation:

After launching PowerShell, go ahead, type Login-AzureRmAccount, and hit Enter.  When prompted for your Azure credentials supply them and click Sign In.

Once you’ve signed in, it’s time to create your resource group, which will contain all of the resources you are about to create.

Create a resource group

Before you create your resource group, you need to decide where you are going to create it and what you are going to name it.  To get a list of available locations where resources can be created, type the following command in PowerShell and hit Enter:

Get-AzureRmLocation | sort Location | Select Location

After hitting Enter, you will be provided with a number of Locations to choose from.

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.