Saturday, May 31, 2014

Start and Stop your AX2012 R3 Azure Demos using PowerShell

There are tons of blog posts covering how to use PowerShell to control your Azure components, services, machines, etc. Once you download and install PowerShell for Azure and try it yourself, you see how easy you can manage Azure by running some simple commands. This post is here to help you AX'ers who have already started playing with Life Cycle Services and Cloud hosted AX2012 R3 Demos. You should be aware that each demo you create will cost money while it is running, so here is a post on how you can easily start and stop them using simple scripts instead of doing it through the Azure management portal.

I am going to assume your user is admin or co-admin on Azure, or you at least have credentials for such a user. I'm also going to assume you've downloaded PowerShell for Azure and installed it.

Start by opening PowerShell for Azure.


Run this command to authenticate for the next 12 hours:

Add-AzureAccount

You will be prompted for credentials, and you need to provide the same credentials you would be using if you were authenticating against Azure.

Use this command to Start demos:

Get-AzureService | Where-Object {$_.Label -match "AX2012R3"} | `
Foreach-Object { Start-AzureVM -ServiceName $_.ServiceName -Name "*" –Verbose }

If you change the filter part ("AX2012R3"), you could control a subset of your services based on some naming pattern or convention.

Use this command to Stop the demos:

Get-AzureService | Where-Object {$_.Label -match "AX2012R3"} | `
Foreach-Object { Stop-AzureVM -ServiceName $_.ServiceName -Name "*" –Force –Verbose }

Isn't that cool?

Now for the bonus part. When you create these demos, you access them through RDP-files. Here is a PowerShell command to download the RDP-files and save them to disk:

Get-AzureService | Where-Object {$_.Label -match "AX2012R3"} | `
Get-AzureRole -InstanceDetails | Where-Object {$_.RoleName -Match "DEMO" } | `
Foreach-Object { Get-AzureRemoteDesktopFile -ServiceName $_.ServiceName -Name $_.InstanceName `
-LocalPath (Join-Path "C:\Temp" ($_.InstanceName + ".rdp")) }

Pretty neat, ey? :-)

No comments:

Post a Comment