英文:
How can I list webapp extensions using Azure CLI?
问题
我需要在约50个Azure应用服务上移除一个站点扩展。
az webapp 命令空间没有列出站点扩展的任何内容:https://learn.microsoft.com/en-us/cli/azure/webapp?view=azure-cli-latest
Azure团队不会触及站点扩展:https://github.com/Azure/azure-cli/issues/7617
然而,一条评论显示如果你知道资源ID,可以删除扩展:https://github.com/Azure/azure-cli/issues/7617#issuecomment-952743871
这个命令不会返回已安装的扩展:
az resource list --resource-type Microsoft.Web/sites
而这个命令什么也不返回:
az resource list --resource-type Microsoft.Web/sites/siteextensions
那么我如何使用Azure CLI获取已安装的Web应用扩展列表?
英文:
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?
答案1
得分: 1
以下是您要求的翻译内容:
即使我使用以下命令无法获取扩展列表
az resource list --resource-type Microsoft.Web/sites
不要使用`az resource list`,而要使用`az resource show`。
```csharp
az resource show --resource-group 'YourRGName' --resource-type 'Microsoft.Web/sites/siteextensions' --name 'mywebapp15June/siteextensions'
此命令仅在提供Web应用程序名称时才有效。一次只能检索一个Web应用程序。
要检索所有Web应用程序的扩展,需要在循环中运行上述命令。
我尝试使用Bash
在循环中运行该命令。
RG="YourRGName"
AppNames=$(az webapp list --resource-group $RG --query "[].name" -o tsv)
for AppName in $AppNames; do
echo "WebApp: $AppName"
extensions=$(az resource show --resource-group $RG --resource-type Microsoft.Web/sites/siteextensions --name "$AppName/siteextensions")
echo "站点扩展:"
echo $extensions.title
echo "=========================="
done
输出:
Web应用程序中安装了扩展的将被列出。
<details>
<summary>英文:</summary>
Even Iam unable to get the Extensions list with `
az resource list --resource-type Microsoft.Web/sites
` command.
![enter image description here](https://i.stack.imgur.com/mlHKi.png)
Instead of `az resource list` use show `az resource show`.
```csharp
az resource show --resource-group 'YourRGName' --resource-type 'Microsoft.Web/sites/siteextensions' --name 'mywebapp15June/siteextensions'
- 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"
extensions=$(az resource show --resource-group $RG --resource-type Microsoft.Web/sites/siteextensions --name "$AppName/siteextensions")
echo "Site Extensions:"
echo $extensions.title
echo "=========================="
done
Output:
The webapps which has extensions installed will be listed.
答案2
得分: 1
你可以使用 WebApps -List Site Extensions REST API 来获取特定 Web 应用程序中安装的扩展列表。
您需要使用 PowerShell 编写一个自定义脚本,使用上述 REST API。以下是示例脚本,请根据您的需求进行修改。
Connect-AzAccount
$token = (Get-AzAccessToken).Token
$subscriptionId= "<SubscriptionId>"
$webappList= Get-AzWebApp
Write-Output "List of webapp extensions installed:"
foreach ($item in $webappList) {
$url = 'https://management.azure.com/subscriptions/' + $subscriptionId + "/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
$installedExtensions = (ConvertFrom-Json $extension).value.name
Write-Output $installedExtensions
}
英文:
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.
<!-- begin snippet: js hide: false console: true babel: false -->
<!-- language: lang-html -->
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
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论