Using Out-GridView to simplify selecting the region when managing Microsoft Azure with PowerShell

You've signed up for a Microsoft Azure account and you've installed the Azure Resource Manager PowerShell cmdlets on your computer.

1Install-Module -Name AzureRM -Force


You login to Azure from PowerShell. You'll normally see most people use Login-AzureRmAccount, but that command is an alias (Login isn't an approved verb).

1Get-Alias -Definition Add-AzureRmAccount


Login to Azure and provide the account login information when prompted:



Several of the cmdlets in the Azure Resource Manager PowerShell module require a location (a region) to be specified when creating things. To me, showing the regions in the PowerShell console, figuring out which region I want, and then storing it in a variable is a bit haphazard.



I've found that using Out-GridView makes the process simpler:

1$Region = (
2    Get-AzureRmLocation |
3    Sort-Object -Property Location |
4    Select-Object -Property Location, Displayname |
5    Out-GridView -OutputMode Single -Title 'Select an Azure Region'


Now the region that I selected is stored in a variable that I can use when creating items in Azure:



Although the Out-GridView cmdlet existed in PowerShell version 2.0, you'll need PowerShell version 3.0 to use it as shown in this blog article. The OutputMode parameter of Out-GridView which is used in this blog article was added in PowerShell version 3.0. Also, Out-GridView can only be used on operating systems with a GUI (it cannot be used on server core).

As far as I know, there's no way to set a default region in Azure like there is with the AWS Initialize-AWSDefaultConfiguration cmdlet. I guess if you really wanted to set a default, you could always use $PSDefaultParameterValues to set a default value for the Location parameter for the cmdlets that require it.