I'm running a Self Hosted Windows Agent in Azure DevOps. I have installed PowerShell Core 6.2.3 and as the Administrator installed the Az module so that it is available to all users.
When I run a build using the Azure PowerShell task (V4) - marking as "Use PowerShell Core" and the "Latest Version" of Azure PowerShell I receive the following message:
==============================================================================
Task : Azure PowerShell
Description : Run a PowerShell script within an Azure environment
Version : 4.159.3
Author : Microsoft Corporation
Help : [Learn more about this task](https://go.microsoft.com/fwlink/?LinkID=613749)
==============================================================================
Added TLS 1.2 in session.
Disconnect-AzureRmAccount -Scope Process -ErrorAction Stop
##[warning]Run Connect-AzureRmAccount to login.
##[error]Could not find the modules: 'Az.Accounts' with Version: ''. If the module was recently installed, retry after restarting the Azure Pipelines task agent.
If I run the script on a Hosted Agent it works fine. I can't work out why it fails. I assume it is something different in the profile or environment that the build agent runs under - but I'm not sure how to check this.
On the build agent if I open a PSCore window and run:
Get-Module Az -ListAvailable
It finds the module correctly.