【问题标题】:How to access Azure resources through powershell?如何通过powershell访问Azure资源?
【发布时间】:2022-09-27 14:41:24
【问题描述】:

只想知道如何通过powershell获取门户中的服务总线

我能够通过这段脚本访问应用程序见解

az monitor  app-insights component show | ConvertFrom-Json

现在我希望通过 powershell 访问服务总线、应用服务和应用服务计划

我正在使用这个

az monitor  servicebus component show | ConvertFrom-Json

服务总线,但它不工作。

    标签: azure powershell


    【解决方案1】:

    您在那里使用 Azure CLI,而不是 PowerShell 模块。 如果要列出/显示以下服务的详细信息,则需要使用相应的 Azure CLI 命令:

    1. 服务总线

      az servicebus namespace show --resource-group myresourcegroup --name mynamespace

      参考:https://learn.microsoft.com/en-us/cli/azure/servicebus/namespace?view=azure-cli-latest#az-servicebus-namespace-show

    2. 应用服务

      az webapp show --name MyWebapp --resource-group MyResourceGroup

      参考:https://learn.microsoft.com/en-us/cli/azure/webapp?view=azure-cli-latest#az-webapp-show

    3. 应用服务计划

      az appservice plan show --name MyAppServicePlan --resource-group MyResourceGroup

      参考:https://learn.microsoft.com/en-us/cli/azure/appservice/plan?view=azure-cli-latest#az-appservice-plan-show

      这是完整的 CLI 参考:https://learn.microsoft.com/en-us/cli/azure/reference-index?view=azure-cli-latest

    【讨论】:

      【解决方案2】:

      要获取当前订阅中的服务总线命名空间列表,请使用以下命令:

      az servicebus namespace list
      

      要获取服务总线队列列表,请执行以下命令:

      az servicebus queue list --resource-group myresourcegroup --namespace-name mynamespace
      

      如果您想要主题,请在上面的命令中保留主题代替队列。

      如果您想获取应用服务计划,请使用以下命令:

      az appservice plan list
      

      或者,您可以对 servicebus 使用如下所示的 azure 资源图查询:

      resources
      | where type =~ 'microsoft.servicebus/namespaces'
      

      您可以使用如下所示的 azure 资源图查询来获取应用服务:

      resources
      | where type == 'microsoft.web/sites'
      

      参考资料来自:

      编辑:

      是的,如果您想要 apim 使用以下查询:

      resources
      | where type == "microsoft.apimanagement/service"
      

      使用 cli 获取 apim :

       az account set -s "Subscription name"
          $Resources = az resource list   
          $Resources | Where type -in "Microsoft.ApiManagement/service"
      

      【讨论】:

      • APIM 怎么样?
      • 我已经编辑了我的答案,包括 apim。
      • 如何基于订阅访问apim,我不想给出rg名称和服务名称,只想提供订阅并从该特定订阅中获取apim
      • 我已经编辑了我的答案,包括 apim 而不使用 rg 名称
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-07-10
      • 2018-03-26
      • 2023-04-10
      • 1970-01-01
      • 2021-08-27
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多