-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1b8b6a1
commit 31a3a07
Showing
1 changed file
with
81 additions
and
0 deletions.
There are no files selected for viewing
81 changes: 81 additions & 0 deletions
81
content/posts/2023-03-24-use-powershell-to-retrieve-azure-location-information.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
--- | ||
categories: | ||
- Microsoft Azure | ||
- PowerShell | ||
date: 2023-03-24T18:30:00+01:00 | ||
draft: false | ||
lastMod: 2023-03-24T18:30:00+01:00 | ||
tags: | ||
- Microsoft Azure | ||
- PowerShell | ||
title: Use PowerShell to retrieve Azure location information | ||
--- | ||
|
||
In this post, I'll show you how to retrieve Azure location names using | ||
PowerShell; specifically, using the Azure Az PowerShell module. | ||
|
||
## Install the Azure Az PowerShell module | ||
|
||
We're going to follow [this guide on Microsoft Learn](https://learn.microsoft.com/en-us/powershell/azure/install-az-ps) | ||
to install the Azure Az PowerShell module. | ||
|
||
I'm going to assume that you have the latest version of PowerShell installed. | ||
If you don't, you can follow [this guide on Microsoft Learn](https://learn.microsoft.com/en-us/powershell/scripting/install/installing-powershell). | ||
|
||
Run the following command in a PowerShell session: | ||
|
||
```powershell | ||
Install-Module -Name Az -Scope CurrentUser -Repository PsGallery -Force | ||
``` | ||
|
||
You'll need to authenticate Azure PowerShell by signing in with your Azure | ||
credentials. | ||
|
||
```powershell | ||
Connect-AzAccount | ||
``` | ||
|
||
## Using the `Get-AzLocation` cmdlet | ||
|
||
You can run the `Get-AzLocation` cmdlet without any filtering to return | ||
information such as latitude, longitude, physical location, region type, etc. | ||
Here, we're going to filter to retrieve _only_ the location names, e.g. the | ||
`Location` of each object returned. | ||
|
||
```powershell | ||
Get-AzLocation | Select Location | ||
``` | ||
|
||
This will return a formatted table containing only the 'unfriendly' version of | ||
each location, e.g. 'eastus', 'uksouth', etc. If you're looking to include | ||
Azure location information in a Bicep file, for example, chances are that this | ||
is the value that you're looking for. | ||
|
||
```powershell | ||
Location | ||
-------- | ||
eastus | ||
eastus2 | ||
``` | ||
|
||
If you wanted to expand your returned results to also include the 'friendly' | ||
version of each location, you can. | ||
|
||
```powershell | ||
Get-AzLocation | Select DisplayName,Location | ||
``` | ||
|
||
This will return a formatted table containing the 'friendly' and 'unfriendly' | ||
version of each location. | ||
|
||
```powershell | ||
DisplayName Location | ||
----------- -------- | ||
East US eastus | ||
East US 2 eastus2 | ||
``` | ||
|
||
## Further reading | ||
|
||
Further information on the `Get-AzLocation` cmdlet can be found on | ||
[Microsoft Learn](https://learn.microsoft.com/en-us/powershell/module/az.resources/get-azlocation). |