Share via


How to Start/Stop Azure Resource Manager Virtual Machines with PowerShell

This post will help you to Start/Stop Azure Resource Manager Virtual Machine using PowerShell.

What you need to run this script:

  1. Azure Subscription
  2. Existing Resource Group
  3. Existing Virtual Machines to be Stopped/Started

###########Script to Stop Virtual Machines

 

# Login On Azure

Login-AzureRmAccount

 

# Global Variables

$myResourceGroup="myResourceGroup"
$VMs=@("VM1","VM2","VM3")


Foreach($VM in $VMs)
{
Stop-AzureRmVM -ResourceGroupName $myResourceGroup -Name $VM -Force
}

 

 

###########Script to Start Virtual Machines

 

# Login On Azure

Login-AzureRmAccount

 

# Global Variables

$myResourceGroup="myResourceGroup"
$VMs=@("VM1","VM2")


Foreach($VM in $VMs)
{
Start-AzureRmVM -ResourceGroupName $myResourceGroup -Name $VM
}