Start an Azure VM With PowerShell

This PowerShell blog post will show you how to start a virtual machine that runs on Microsoft Azure using the Az PowerShell module.

Az Module

The Azure Az PowerShell module is a cross-platform module that runs on Windows, macOS and Linux under PowerShell 6 (core) and above. In this post, we are using the latest stable version of PowerShell 7, which is 7.1.3. To check which version of PowerShell, you have run the following commands.

$PSVersionTable

Connect to Azure

To get started, Let’s first login to Azure using the Az module and the following commands.

connect-azaccount -Device

If you have multiple subscriptions attached to your tenant, run the following command to set the right one.


Get-AzSubscription  # List all the subscriptions
Get-AzContext   # Check which subscription you are using 
Set-AzContext -Subscription pay-as-you-go  # Set subscription

Check Status and Start VM

Below I have listed three cmdlets that will help you start the correct VM. The first cmdlet will output all the VMs that you have under the subscription with a lot of details about each VM. This output is a bit messy but it is useful.

get-azvm  

The cmdlet below is much cleaner and will only output the status of each VM (deallocated, running, starting, etc) which help to verify the VM is actually on or off.

get-azvm -status | ft  

The last command,will start the VM and boot it

AzVM -ResourceGroupName ubuntu-resources -Name ubuntu-machine   

For more PowerShell articles please visit the PowerShell category page.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.