I am trying to get all apps in an Azure App service. Because i want to see which are the orphaned App Service Plans.
I have started with this so far:
<Login-to-Azure>
#Get app service plans
$app_service_plans=$(az appservice plan list --query "[].{Name:name,
ResourceGroup:resourceGroup}" --output tsv)
foreach ($app in $app_service_plans)
{
$app_count=$(az webapp list --query "[?serverFarmId=='/subscriptions/${subscription_id}/resourceGroups/${resource_group}/providers/Microsoft.Web/serverfarms/${plan_name}'].{Name:name}" --output tsv )
write-host($app_count)
}
Is this the correct approach ? I want to get al the App Service Plans that have no apps and also all Storage Accounts that are orphaned.
How can i do this ?
1
To get orphaned or unused App service plans you can use below Azure CLI command and I followed Document:
$rith=az graph query -q "
resources
| where type =~ 'microsoft.web/serverfarms'
| where properties.numberOfSites == 0
| project App_Service_Plan_Name=name, Location=location, Res_Grp_Name=resourceGroup
" | ConvertFrom-Json
$rith.data
Output:
Edit:
I have followed Microsoft-Document and below command worked for me:
Get-AzAppServicePlan | Where-Object {$_.NumberOfSites -eq 0}
Output:
Recognized by Microsoft Azure Collective
10