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:
- Azure Subscription
- Existing Resource Group
- 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
}