skip to Main Content

I have these tasks in a pipeline I’m using that is failing because it is using Az.Accounts version earlier than 2.19.0 (2.17.0)

- task: PowerShell@2
  displayName: 'Install Az.Accounts'
  inputs:
    pwsh: true
    targetType: 'inline'
    script: 'Install-Module -Name Az.Accounts -RequiredVersion 2.19.0 -Repository PSGallery -Force
- task: AzurePowerShell@5
  displayName: 'Export Cost Datea
  inputs:
    pwsh: true
    azureSubscription: $serviceconnection
    azurePowerShellVersion: LatestVersion
    scriptType: 'inlineScript'
    inline: |
      Update-Module -Name "Az.Accounts" -Force 
      Get-InstalledModule -Name "Az.Accounts"
      Get-Module -ListAvailable
      $azTenantId = (Get-AzContext).Tenant.Id
      Write-host (Get-AzTenant | where-object Id -eq $azTenantId).Name
      Install-Module Az.CostManagement -Scope CurrentUser -Force
      Import-Module Az.CostManagement
      Invoke-AzCostManagementExecuteReport -ExportName $costExport -Scope $scope

Essentially its just the invoke cost management export and all the other code is just there to get it to work. I can see that both versions are installed when I list the modules. How do I make the pipeline use the correct version?

I tried using this fix Azure Devops pipeline failing due to AZ.Accounts Module update by MSFT but it is no longer working.

I also added the update module Line but it hasnt worked either and its still throwing the error:

This module requires Az.Accounts version 2.19.0. An earlier version of Az.Accounts is imported in the current PowerShell session. Please open a new session before importing this module. This error could indicate that multiple incompatible versions of the Azure PowerShell cmdlets are installed on your system. Please see https://aka.ms/azps-version-error for troubleshooting information.
##[error]PowerShell exited with code ‘1’.

enter image description here

enter image description here

enter image description here
enter image description here

2

Answers


  1. The default versions of Az.Accounts on ubuntu-latest and windows-latest are both 2.17.0.

    Using Install-Module -Name Az.Accounts -RequiredVersion 2.19.0 -Repository PSGallery -Force to install the module Az.Accounts 2.19.0, it works fine whether using ubuntu-latest or windows-latest in my pipeline.

    You can try again with windows-latest and share the error message, if any.


    Update

    You can use azure powershell 11.6.0. The version of Az.Accounts in azure powershell 11.6.0 is 2.19.0 by default. Replace azurePowerShellVersion: LatestVersion with preferredAzurePowerShellVersion: '11.6.0' in your AzurePowerShell@5 task.

    Login or Signup to reply.
  2. This looks like a repeatable issue, see https://github.com/microsoftgraph/msgraph-sdk-powershell/issues/2745

    It sounds like most users got a temporary workaround by downgrading Microsoft.Graph.Applications to 2.17.0

    Install-Module Microsoft.Graph.Applications -Force -AllowClobber -RequiredVersion 2.17.0
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search