skip to Main Content

I need to remove a Site Extension across ~50 Azure App Services.
The az webapp command space doesn’t list anything for Site Extensions: https://learn.microsoft.com/en-us/cli/azure/webapp?view=azure-cli-latest

The Azure team won’t touch Site Extensions: https://github.com/Azure/azure-cli/issues/7617

However, a comment shows it’s possible to delete the extension, if you know the resource ID: https://github.com/Azure/azure-cli/issues/7617#issuecomment-952743871

This command does not return installed extensions:

az resource list --resource-type Microsoft.Web/sites

And this command returns nothing:

az resource list --resource-type Microsoft.Web/sites/siteextensions

So how can I get a list of installed webapp extensions with Azure CLI?

2

Answers


  1. Even Iam unable to get the Extensions list with az resource list --resource-type Microsoft.Web/sites command.

    enter image description here

    Instead of az resource list use show az resource show.

    az resource show --resource-group 'YourRGName' --resource-type 'Microsoft.Web/sites/siteextensions'  --name 'mywebapp15June/siteextensions'                    
    

    enter image description here

    • This command work only if we provide the webapp name. At a time, we can retrieve only 1 webapp.
    • To retrieve the extensions for all the webapps, need to run the above command in loop.

    I have tried to run the command in loop using Bash.

    RG="YourRGName"
    AppNames=$(az webapp list --resource-group $RG --query "[].name" -o tsv)
    
    for AppName in $AppNames; do
        echo "WebApp: $AppName"
        
        # Retrieve the site extensions for the web app
        extensions=$(az resource show --resource-group $RG --resource-type Microsoft.Web/sites/siteextensions --name "$AppName/siteextensions")
        
        # Display the site extensions information
        echo "Site Extensions:"
        echo $extensions.title
        echo "=========================="
    done
    

    Output:

    enter image description here

    enter image description here

    The webapps which has extensions installed will be listed.

    Login or Signup to reply.
  2. You can use WebApps -List Site Extensions REST API to pull the list of extensions installed in the specific webapp.

    You Need to write a custom script using the above rest API in PowerShell.

    Here is the sample script and please do modify it accordingly based on your requirement.

    Connect-AzAccount
    
    $token = (Get-AzAccessToken).Token
    
    $subcriptionId= "<SubscriptionId>"
    
    $webapplist= Get-AzWebApp 
    
    Write-output "List of webapp extensions installed:"
    
    foreach ( $item in $webapplist) {
    
    $url = 'https://management.azure.com/subscriptions/' + $subcriptionId + "/resourceGroups/" + $item.ResourceGroup + "/providers/Microsoft.Web/sites/" + $item.Name + "/siteextensions?api-version=2022-03-01"
     
    $extension= Invoke-WebRequest -Method Get -Uri $url -Headers @{'authorization'= "Bearer " + $token } -ContentType "application/json" | Select -ExpandProperty Content
    $installedextenstions = (ConvertFrom-Json $extension).value.name
    
    
    Write-Output $installedextenstions
    
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search