Browsing Azure With Powershell

Browsing Azure With Powershell

Ever since my post about automated deployments of Azure VMs with SQL Server, I've been pondering on how to pick the best locations and to understand what exactly it is under the hood that you actually use with PowerShell. In a nutshell, Azure follows a structure called the Azure Resource Manager (ARM). Unfortunately, ARM is not human-readable, so you need to a tool to be efficient in using it. There are quite some tools available, and from Microsoft, there is Azure Bicep, Azure CLI and Azure PowerShell. Since I have done some DBA stuff in the past, and I am a fan of [dbatools](https://dbatools.io/) ([created by the team here](https://dbatools.io/team/)), I find PowerShell the most convenient tool to use and suspect that many will see it the same way if they are using dbatools. Additionally, I've showcased the following code during some User Groups and with this post, I am retiring this session unless it'll get explicitly requested. So the premise of this post is that you are a solution architect and you're wondering where you want to deploy your resources to. You can go to the [Azure Virtual machines selector](https://azure.microsoft.com/en-us/pricing/vm-selector/) by Microsoft, however I always found this a bit cumbersome to use. And with PowerShell, you are actually able to get more information than you would get from the VM selector, except for the pricing. So in this demo, I am going to show you how to use PowerShell to browse through the Azure locations and to find the best location for your resources. It is best to use the cloud shell that you'll find in your Azure portal. If you want to use your local PowerShell, this should be possible as well, but I haven't tested this lately. If you choose to use to do this via local powershell, don't forget to login to your account and it is always a good idea to check first in which subscription you are working, regardless of you're using the cloud shell or your local one:

Here, you'll find the cloud shell
Connect-AzAccount # login to your account if you're using local PowerShell - skip this if you're using the cloud shell 

Get-AzSubscription # get the current subscription 

Get-AzContext # check the context          

So now, lets see how we can browse through the locations, beginning with a global view, the so-called geography groups:

Get-AzLocation | Select-Object GeographyGroup | `
    Sort-Object -Property GeographyGroup -Unique        

and you'll get something like this:

and you'll get something like this:View over GeographyGroup

and if you know the Azure VM selector, you'll have something like here:

The GeographyGroup & Regional Overview in Azure VM Selector

Actually, this view is something like a merge from the prior code and this one, the logical regions:

# Get the view over logical regions
Get-AzLocation | where-object { $_.RegionType -eq "Logical" } | `
Select-Object DisplayName, RegionType | Format-Table -AutoSize        

Now, we're curious and want to know all regions including their physical regions - something you won't find in the Azure VM selector:

Get-AzLocation | Select-Object DisplayName, Location, `
    GeographyGroup, RegionType, PhysicalLocation | `
    Sort-Object DisplayName | Format-Table -AutoSize        

With this view, it is perhaps a bit more clear what GeographyGroup and RegionType (logical or physical) means. Additionally, you'll the locations of each Display Name or its technical name "Location". As an example, Switzerland North is located in Zurich, Switzerland, whereas "Switzerland West" is located in Geneva, Switzerland.

We also can filter this a bit, like for Europe alone:

Get-AzLocation | Where-Object { $_.geographyGroup -eq 'Europe' } | `
    Select-Object DisplayName, Location, PhysicalLocation, pairedRegion | `
    Sort-Object DisplayName | Format-Table -AutoSize        

Now, because we have this in a programming language, we can of course do all kinds of stuff with it, like just counting the locations:

(Get-AzLocation | Select-Object DisplayName, Location).count        

This currently gives me 74 locations, but this number can change over time, so you might get a different number if you run this code in future. For Europe alone, we can do this:

Now, as a solution architect, you may want to pick a location that is a) close to you and b) provides most services, especially those you're interested in. So let's see how we can get the count of service providers of each location:

Get-AzLocation | Where-Object { $_.geographyGroup -eq 'Europe' } | `
    ForEach-Object { [PSCustomObject]@{DisplayName = $_.DisplayName; `
            RegionCategory = $_.RegionCategory; PhysicalLocation = $_.PhysicalLocation; `
            ProviderCount = $_.Providers.Count 
    } } | `
    Sort-Object ProviderCount -Descending | Format-Table -AutoSize        

So we see that in Europe, West Europe has the most providers, followed by North Europe and UK South. My hometown Zurich, Switzerland is still in mid range, but Geneva, (Switzerland West) is falling a bit short.

Overview of provider counts with PhysicalLocations in Europe

We of course can filter this further, like for the providers of the Microsoft.Fabric service:

Get-AzLocation | Where-Object { $_.geographyGroup -eq 'Europe' `
 -and $_.Providers -contains 'Microsoft.Fabric' } | Sort-Object DisplayName | `
    Format-Table -Property DisplayName -AutoSize        

Yeah, that seems to be pretty much everywhere in Europe, so let's see what regions do not provide Fabric:

Get-AzLocation | Where-Object { $_.RegionType -eq 'Physical' `
        -and $_.Providers -notcontains 'Microsoft.Fabric' } | `
    Sort-Object DisplayName | Format-Table -Property DisplayName, PhysicalLocation -AutoSize        
Answer of which locations do not provide Fabric

So we see that only a handful of places do not provide Fabric, like Canberra and Rio De Janeiro. Central US EUAP and East US 2 EUAP are a special case of themselves, you can read more about it here.

We also can do comparisions between locations of course. For example, I'm interested to know which services are not available in France Central compared to West Europe:

$westeurope = Get-AzLocation | Where-Object { $_.DisplayName -eq 'West Europe' }
$francecentral = Get-AzLocation | Where-Object { $_.DisplayName -eq 'France Central'}
$westeurope.Providers | Where-Object { $francecentral.Providers -notcontains $_ }        

For VMs, we also have the possibility to do research like on the VM selector, but we have a bit more flexibility in doing so:

Get-AzVMSize -Location 'westeurope' | `
    Where-Object { $_.NumberOfCores -ge 16 -and $_.NumberOfCores -le 32 `
        -and $_.MemoryInMB -gt 64000 -and $_.MemoryInMB -lt 120000 }        

And we also can count again, very easily:

(Get-AzVMSize -Location 'westeurope' | `
    Where-Object { $_.NumberOfCores -ge 16 `
        -and $_.NumberOfCores -le 32 `
        -and $_.MemoryInMB -gt 64000 `
        -and $_.MemoryInMB -lt 120000 }).count        

Get information what kind of servers are availabe in a location, is possible too. Note that we can see that we have different kinds of Windows Servers, but also Linux Servers (Red Hat (RHEL), Ubuntu and Suse (SLES)) and and also if we can BYOL (Bring Your Own License) or not:

Get-AzVMImageOffer -Location 'westeurope' `
    -PublisherName 'MicrosoftSQLServer' | select Offer, PublisherName        

We also can drll down this more. You want to know if there's SQL Server Developer Edition? This is something you can't see in VM selector, but with PowerShell:

Get-AzVMImageSku -Location 'westeurope' `
    -PublisherName 'MicrosoftSQLServer' -Offer 'sql2019-ws2022' | `
    select Skus, Offer, PublisherName, Location        

I hope this post is helpful for some! If you have any questions, feel free to ask!

This post was first published on my personal blog here: Browsing Azure With Powershell | Kay On Data

Andy Cutler

Owner at Datahai BI Solutions | Microsoft Data Platform MVP | I help unlock the potential of Microsoft Data technologies

4 个月

PowerShell is very useful for working with Azure, great post!

Dennes Torres

Data Platform MVP (2020-2023) | Certified Expert in Fabric Analytics Engineering, Azure Data Engineering, Solutions Architecture, DevOps, and Development

4 个月

This is very interesting and a important subject. I remember when I was teaching about Azure and SQL, explaining about SQL in Virtual Machines, how to choose the disks with the correct throughput needed, match the disks throughput with the vm throughput, decide about having disk bursting and vm bursting enabled, we end up concluding in class the best way to find combinations of VMs and disks to build a SQL machine in the way we need is using powershell to search the properties of each element

Rod Edwards

SQL Server Tech / DBA / DRE

4 个月

Great post ??

Kevin Chant

Data Engineering Manager & Data Platform MVP in Microsoft Fabric Technology area. Co-organizer of both DataWeekender conference and Dutch Fabric User Group.

4 个月

Interesting read.

Great example, thank you for the insight

要查看或添加评论,请登录

社区洞察

其他会员也浏览了