你可以使用 Azure CLI 如何列出 Web 应用程序扩展?

huangapple go评论66阅读模式
英文:

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 &#39;YourRGName&#39; --resource-type &#39;Microsoft.Web/sites/siteextensions&#39;  --name &#39;mywebapp15June/siteextensions&#39;                    

你可以使用 Azure CLI 如何列出 Web 应用程序扩展?

  • 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=&quot;YourRGName&quot;
AppNames=$(az webapp list --resource-group $RG --query &quot;[].name&quot; -o tsv)

for AppName in $AppNames; do
    echo &quot;WebApp: $AppName&quot;
    
    extensions=$(az resource show --resource-group $RG --resource-type Microsoft.Web/sites/siteextensions --name &quot;$AppName/siteextensions&quot;)
    
    echo &quot;Site Extensions:&quot;
    echo $extensions.title
    echo &quot;==========================&quot;
done

Output:

你可以使用 Azure CLI 如何列出 Web 应用程序扩展?

你可以使用 Azure CLI 如何列出 Web 应用程序扩展?

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= &quot;&lt;SubscriptionId&gt;&quot;

$webapplist= Get-AzWebApp 

Write-output &quot;List of webapp extensions installed:&quot;

foreach ( $item in $webapplist) {

$url = &#39;https://management.azure.com/subscriptions/&#39; + $subcriptionId + &quot;/resourceGroups/&quot; + $item.ResourceGroup + &quot;/providers/Microsoft.Web/sites/&quot; + $item.Name + &quot;/siteextensions?api-version=2022-03-01&quot;
 
$extension= Invoke-WebRequest -Method Get -Uri $url -Headers @{&#39;authorization&#39;= &quot;Bearer &quot; + $token } -ContentType &quot;application/json&quot; | Select -ExpandProperty Content
$installedextenstions = (ConvertFrom-Json $extension).value.name


Write-Output $installedextenstions

}

huangapple
  • 本文由 发表于 2023年6月16日 05:45:19
  • 转载请务必保留本文链接:https://go.coder-hub.com/76485719.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定