frameworkResources/Scripts/list_all_environments.ps1
function ShowEnvs { Write-Host "Fetching Environments..." $all_resource_groups = Get-AzResourceGroup -ErrorAction Stop | Where-Object { $_.Tags -and $_.Tags.ContainsKey("EnvironmentName") } if (-not $all_resource_groups) { Write-Output "No Environments Found" } else { Write-Output $all_resource_groups | Select-Object @{Name = "EnvironmentName"; Expression = { $_.Tags["EnvironmentName"] } }, @{Name = "OS"; Expression = { $_.Tags["OsType"] } }, @{Name = "ServerProfile"; Expression = { $_.Tags["ServerProfile"] } }, @{Name = "Version"; Expression = { $_.Tags["Version"] } }, Location, ResourceId } } if (-not (Get-AzContext)) { Connect-AzAccount if (Get-AzContext) { ShowEnvs } } else { ShowEnvs } |