【问题标题】:Get-AzApplicationInsights is not recognized无法识别 Get-AzApplicationInsights
【发布时间】:2021-03-04 01:25:24
【问题描述】:

我构建了一个新的 Azure 管道并添加了这个“Azure CLI”任务来尝试运行一些 Azure CLI Powershell 脚本。首先,我想对现有的 AppInsights 资源进行一些检查。 (Azure CLI) https://github.com/microsoft/azure-pipelines-tasks/blob/master/Tasks/AzureCLIV2/Readme.md

在 Azure CLI 任务中运行“Get-AzApplicationInsights”时出现此错误。

'Get-AzApplicationInsights' : The term 'Get-AzApplicationInsights' is not recognized as the name of a cmdlet, function.

整个 yaml 脚本如下所示:

steps:
- task: AzureCLI@2
  displayName: 'Azure CLI Powershell'
  inputs:
    azureSubscription: ####
    scriptType: ps
    scriptLocation: inlineScript
    inlineScript: |
     Write-Output "RESULTS:"
     az config set extension.use_dynamic_install=yes_without_prompt
     Get-AzApplicationInsights -ResourceGroupName ############# -Name ############## Select-String -Pattern "PricingPlan"

关于无法识别 cmdlet 的原因,我是否遗漏了什么?我应该先导入一个模块吗?

【问题讨论】:

  • 您好,如果这个答案有帮助,您会接受它作为答案吗?因此,它可以帮助遇到相同问题的其他社区成员,我们可以存档此线程。谢谢。祝你今天过得愉快。 :)

标签: azure-devops azure-pipelines azure-cli azure-yaml-pipelines


【解决方案1】:

要运行 Azure powershell Get-AzApplicationInsights,只需在 Azure PowerShell task 中运行即可。

或者如果你想使用 Azure CLI 任务,你可以直接使用 CLI 命令az monitor app-insights component show 而不是 powershell 命令。

【讨论】:

    【解决方案2】:

    同意Joy Wang。

    检查docGet-AzApplicationInsights 是 power shell CMD 安装还是 Azure CLI,我们应该通过任务 Azure Power Shell 而不是 Azure CLI 任务来运行它。

    构建定义示例:

    - task: AzurePowerShell@5
      displayName: 'Azure PowerShell script: InlineScript'
      inputs:
        azureSubscription: '{Subscription}'
        ScriptType: InlineScript
        Inline: 'Get-AzApplicationInsights -ResourceGroupName "{Resource Group Name}" -Name "{Application Insights name}" -IncludePricingPlan'
        azurePowerShellVersion: LatestVersion
    

    结果:

    【讨论】:

      猜你喜欢
      • 2020-03-31
      • 1970-01-01
      • 1970-01-01
      • 2021-07-02
      • 2015-05-28
      • 1970-01-01
      • 2021-05-01
      • 1970-01-01
      • 2022-01-06
      相关资源
      最近更新 更多