Skip to content

Instantly share code, notes, and snippets.

@omarmciver
Created November 28, 2022 17:25
Show Gist options
  • Save omarmciver/a573c9882c25f75ecb6a7e33790885c4 to your computer and use it in GitHub Desktop.
Save omarmciver/a573c9882c25f75ecb6a7e33790885c4 to your computer and use it in GitHub Desktop.
Get All SQL Servers (or any resource type) #PowerShell #Azure
#az login
$subs = az account list | ConvertFrom-Json
$allServers = @()
foreach($sub in $subs){
Write-Output $sub.Name
az account set -s $sub.Id
$subServers = az resource list --resource-type 'Microsoft.Sql/servers' | ConvertFrom-Json
foreach($server in $subServers){
$allServers += $server
}
}
$allServers | Format-Table -Property name, kind, id
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment