I'm creating a Build Pipeline in Azure DevOps. I have a PowerShell task that invokes a script inside a file - it's not "inline" PowerShell. That script needs the Az.Accounts module so I added Import-Module Az.Accounts. When I run the pipeline, I get the following:
Import-Module : The specified module 'Az.Accounts' was not loaded because no valid module file was found in any module
directory.
At D:\a\1\s\XXX\XXX\XXX.ps1:14 char:1
+ Import-Module Az.Accounts
+ ~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ResourceUnavailable: (Az.Accounts:String) [Import-Module], FileNotFoundException
+ FullyQualifiedErrorId : Modules_ModuleNotFound,Microsoft.PowerShell.Commands.ImportModuleCommand
How do I add the missing module so my script can run?
By default, the hosted windows agent just include the AzureRM module, which is older.With the Az module, Azure PowerShell is now compatible with PowerShell 5.1 on Windows and PowerShell Core 6.x and later on all supported platforms - including Windows, macOS, and Linux.It is the biggest and most important change.
You can add an inline powershell task for installing the Az.Accounts module. 
Please note that if you don't add the -force parameter in the script, you will get this information in process.
User declined to install module (Az.Accounts).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With