I have an Azure DevOps pipeline using the AzurePowerShell@5 task. I pass the service connection to the task and it logs in to Azure. That part is good.
The PowerShell code that is executed by the task calls Get-AzADServicePrincipalAppRollAssignment, which requires the latest Az.Resources 6.16.0. Az.Resources 6.16.0 in turn requires Az.Accounts 2.16.0. However, the AzurePowerShell@5 task installed Az.Accounts 2.15.1.
When I try to remove Az.Accounts 2.15.1 and install the latest version, I get the following error. Not sure how to get around that. Is there a lock on the assembly because it was used to log in to Azure?
I have read about using a PowerShell session to load modules but my hunch is that would log me out of Azure?
I agree with @Galna Greta, The
AzurePowershell@5task will only use the Az version installed on the agent.I tried Installing
Az.Accounts - 2.16.0andAz.Resourcesin Azure Powershell task with Install-Module command but it failed. Thus instead of usingAzurePowershell@5task I used Powershell@2 task like below: -Output: -