Azure Pipeline - The term 'Get-AzKeyVaultSecret' is not recognized as the name of a cmdlet, function, script

Viewed 1962

I have an Azure Pipeline which runs the following command to install the Az.KeyVault module, before going on to run another script (list-keyvault-secrets.ps1) where the installed KeyVault module gets called.

enter image description here

The module gets installed successfully, however when the powershell script that follows gets run, the pipeline fails and displays the below error message.

enter image description here

This is an example of one of the lines of code where the Get-AzKeyVaultSecret command is called:

$plainTxtSecret = Get-AzKeyVaultSecret -VaultName $srckvName -Name $name -AsPlainText

Any idea what could be causing this error and how I can resolve it?

1 Answers

I think you should use the AzurePowerShell Azure DevOps Task. Here an example:

- task: AzurePowerShell@5
  inputs:
    azureSubscription: my-arm-service-connection
    scriptType: filePath
    scriptPath: $(Build.SourcesDirectory)\myscript.ps1
    scriptArguments:
      -Arg1 val1 `
      -Arg2 val2 `
      -Arg3 val3
    azurePowerShellVersion: latestVersion
    pwsh: true
Related