How to Deploy a Virtual Machine in Azure with PowerShell

 

$myNIC = New-AzureRmNetworkInterface -Name "myNIC" -ResourceGroupName $myResourceGroup -Location $location -SubnetId $myVnet.Subnets[0].Id -PublicIpAddressId $myPublicIp.Id

 

At this point, you’ve got the infrastructure prepared and you can now deploy the virtual machine.

Create a virtual machine

Virtual machines can be deployed using both sysprepped and non-sysprepped images.  They can also be deployed from the Marketplace, which is what we are going to do here.

The first thing you’ll want to do is set the admin account and password for your virtual machine.  To do this, run the command below and hit Enter:

 

$cred = Get-Credential -Message "Type the name and password of the local administrator account."

 

When prompted, supply an administrative username and password.  The password must be at least 12 characters long and contain one upper case character, one lower case character, a number, and one special character.

Next, you’ll need to create a configuration object for the virtual machine.  The configuration object includes a name for the virtual machine and a size for the virtual machine.  For this exercise, we’ll name our virtual machine SERVER01 and use the “Standard_DS1_v2” size.

To complete this task, run the following command and hit Enter:

 

$myVM = New-AzureRmVMConfig -VMName "SERVER01" -VMSize "Standard_DS1_v2"

 

Click here for a list of supported server sizes in Azure.

Once you’ve completed the above task, you’ll need to configure the operating system for the virtual machine.  This configuration task sets the computer name, OS type, and account credentials for the VM.  To configure these settings run the following command from PowerShell:

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.