1

I constructed a new Azure Pipeline and added this 'Azure CLI' task to try and run some Azure CLI Powershell scripting. Primarily, I want to do some checks on an existing AppInsights resources. (Azure CLI) https://github.com/microsoft/azure-pipelines-tasks/blob/master/Tasks/AzureCLIV2/Readme.md

I get this error when runnin 'Get-AzApplicationInsights' inside the Azure CLI Task.

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

The whole yaml script looks like this:

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"

Is there something I am missing as to why the cmdlet is not being recognised? Should there be a module I need to first to import?

Don Draper
  • 137
  • 1
  • 3
  • 12
  • Hi, If this answer is helpful, would you please accept it as the answer? So it could help other community members who get the same issues and we could archive this thread. Thanks. Have a nice day. :) – Vito Liu Mar 05 '21 at 09:26

2 Answers2

4

To run the Azure powershell Get-AzApplicationInsights, just run it in the Azure PowerShell task.

Or if you want to use the Azure CLI task, you could use CLI command az monitor app-insights component show directly instead of the powershell command.

Joy Wang
  • 39,905
  • 3
  • 30
  • 54
3

Agree with Joy Wang.

Check this doc, Get-AzApplicationInsights is power shell CMD install or Azure CLI, we should run it via the task Azure Power Shell instead of Azure CLI task.

enter image description here

Build definition sample:

- 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

Result:

enter image description here

Vito Liu
  • 7,525
  • 1
  • 8
  • 17