Azure CLI Task Yaml

247 Views Asked by At

I am trying to execute Get-AzSqlServer from AzureCli@2 yaml pipeline and it is throwing an error: The term 'Get-AzSqlServer ' is not recognized as the name of a cmdlet

Here is my task

- task: AzureCli@2
  inputs:
   azureSubscription: 'serviceconnection'
   scriptType: 'ps'
   scriptLocation: 'inlineScript'
   inlineScript: |
    $sqlServer = Get-AzSqlServer -ResourceGroupName rgTest
2

There are 2 best solutions below

1
Yar On

Try to use:

   pwsh: |    
     $sqlServer = Get-AzSqlServer -ResourceGroupName rgTest
5
Daniel Mann On

Use AzurePowerShell@5 if you want to run PowerShell in an authenticated session.

You could also try running Import-Module for the appropriate Azure PowerShell modules, but I don't guarantee that would work.