0

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
Lucky
  • 81
  • 6

2 Answers2

1

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.

Daniel Mann
  • 57,011
  • 13
  • 100
  • 120
  • I am trying this - task: AzurePowerShell@5 inputs: azureSubscription: 'serviceconnection' ScriptType: InlineScript azurePowerShellVersion: LatestVersion Inline: | $sqlServer = Get-AzSqlServer -ResourceGroupName rgTest – Lucky Apr 12 '23 at 15:45
  • Sorry missed adding, before the $sqlServer I also have Install-Module Az.Sql – Lucky Apr 12 '23 at 15:47
  • AzurePowershell@5 also fails with same issue unfortunately – Lucky Apr 13 '23 at 04:57
  • Are you using a private agent or the Microsoft hosted agent? If you're using a private agent, you *absolutely* need to install the module first. – Daniel Mann Apr 13 '23 at 22:44
  • Private and I did try to install az.sql – Lucky Apr 14 '23 at 14:13
-1

Try to use:

   pwsh: |    
     $sqlServer = Get-AzSqlServer -ResourceGroupName rgTest
Yar
  • 27
  • 5