Start And Stop Microsoft Azure VM Using PowerShell Scripts

In this article I’ll show you two PowerShell scripts that will start and stop a specific Virtual Machine running In Microsoft Azure.

In my case I’m running these scripts from the Windows 10 workstation.

Before you run this make sure you have a Azure VM and You Installed the Azure PowerShell Module.

In the example below I’ll start a VM name NTAP02 running Inside a Resource group called RGAZURE:

Copy the code below PowerShell ISE or notepad, Change the values to match your Azure Environment and either from ISE or PowerShell console using Run As Administrator.

import-module azurerm


Select-AzureRmSubscription - -SubscriptionName "azure pass"

Start-AzureRmVM -ResourceGroupName rgazure -Name ntap02

Once you start the script you will get a prompt to enter your Azure User Name and password

When the VM starts you will see the status below

You can alsocheck the status using:

Get-AzureRmVM -Name ntap02 -Status -ResourceGroupName rgazure

Stop Azure Virtual Machine

To stop a running VM using a PowerShell script use the code below.

Import-module azurerm


Select-AzureRmSubscription - -SubscriptionName "azure pass"

Stop-AzureRmVM -ResourceGroupName rgazure -Name ntap02

When you run the script you will see the message below:

For more article visit our Microsoft Azure Page.