Powershell for stopping and starting Azure VMs
My guess is that you create the virtual machine using the Azure Resource Management (ARM) model. The PowerShell script above use the older, Azure Service Management (ASM) model.
The above script need a few modifications to use the ARM model:
#Login using the ARM modelLogin-AzureRmAccount#Select your subscription if you got multipleSelect-AzureRmSubscription -SubscriptionId xxxxxx-xxxe-xxxx5-8xxxx-e2xxxxxxxx1c#Get a list of exisiting VMsGet-AzureRmVM#Start a vm named 'linux' inside resource group 'lab-rg'Start-AzureRmVM -Name linux -ResourceGroupName lab-rg
If you don't have AzureRM PowerShell commands installed and are running Windows 10, you can easily install them by running
Install-Module AzureRM
ServiceName
specifies the name of the Azure service that contains the virtual machine to shut down.
Incase if you have deployed your VM through classic model, then you will get the ServiceName
.
From the description, looks like you have created the VM through ARM model. I suggest you use Get-AzureRmVM
cmdlet to list the VM's.
To start VM use the below PowerShell cmdlets.
Start-AzureRmVM -ResourceGroupName "YourResourceGroupName" -Name "YourVirtualMachineName"
To stop VM use the below PowerShell cmdlets.
Stop-AzureRmVM -ResourceGroupName "ResourceGroupName" -Name "VirtualMachineName"