The Windows Azure portal is a great resource. It has the full bredth of Azure visually displayed for you to see your Azure subscription and discover new things on the platform. But manually clicking through to provision a new VM or restart a VM isn’t the dream. As much as I think it’s well designed and easy enough to use, when I want to power down a Virtual Machine, I don’t want to have to wait to login to Azure, wait for it to load, find the correct screen and finally click on the action that I need. I want it NOW!
I have several Virtual Machines provisioned in Azure, mostly for testing/demonstrating purposes. Turning them on and off should be as easy as flipping a switch (or at least flipping a script).
I’m running Windows 10, which comes with PowerShell 3.0.
If you haven’t already you will need to allow the execution of scripts in PowerShell with the following command in a PowerShell command prompt.
Set-ExecutionPolicy -ExecutionPolicy Unrestricted
Select Yes when asked if you’re sure.
Next we’re going to install the Azure Resource Manager Module from the PowerShell Gallery
You can do this in a PowerShell Command Prompt with the following:
Now Import all the modules into this session
Now you can login to your Azure subscription using
This brings up the Azure login prompt, I will do another post on how to setup login without having to enter your username & password. For now enter your Azure credentials as you would normally to login to the Azure Portal.
It will display all the Subscriptions you have on that account/email address.
Sweet, so this is the base to begin all your automation actions.
$resourceGroupName = "test-application" $vmName = "test01" Get-AzureRmVM -ResourceGroupName $resourceGroupName -Name $vmName
It’s important to remember to stop the Azure Virtual Machine via this powershell command or in the Azure portal. If you only shutdown the VM from within the VM, you will continue to incur charges from Microsoft.
Stop-AzureRmVM -ResourceGroupName $resourceGroupName -Name $vmName
Start-AzureRmVM -ResourceGroupName $resourceGroupName -Name $vmName
I'm a .NET Software Engineer. Obsessed with Scrum / agile practices, DevOps, Azure... and C# of course
Nant (1) Load testing (1) Visual studio (1) Azure (25) Aws (1) Asp.net (1) Tfs (1) Puppetlabs reports (2) Devops (2) Iis (1) Powershell (7) Arm templates (2) Arm template (1) Azure (9) Arm (2) Powershell (1) Dsc (1) Jekyll (1) Vsts (1) Arm (2)