skip to Main Content

This code is working in my local machine in Powershell ISE, but it is not working in the devops pipeline

$AzureTenantId = "dgfg"
$AzureApplicationId = "fgfgg"
$AzureApplicationSecret = "fdgfghf"

$SecuredApplicationSecret = ConvertTo-SecureString "$AzureApplicationSecret" -AsPlainText -Force
$psCred = New-Object System.Management.Automation.PSCredential($AzureApplicationId , $SecuredApplicationSecret)
Connect-AzAccount -Credential $psCred -TenantId $AzureTenantId -ServicePrincipal

I am getting this error:
The term ‘Connect-AzAccount’ is not recognized as a name of a cmdlet, function, script file, or executable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

What changes I need to need to do so that it also works in the pipeline?

2

Answers


    1. You can install the Az.Accounts Module by adding the following command at the beginning of your PowerShell script.

      Install-Module -Name Az.Accounts -Repository PSGallery -Force
      
    2. You can also change to use the AzurePowerShell task as mentioned by KKI.

    Login or Signup to reply.
  1. In Azure Pipelines, it is recommended using the Azure PowerShell task to execute the Azure PowerShell commands.

    And use an ARM service connection (Azure Resource Manager service connection) on the task to safety connect to Azure.


    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search