Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I import a PowerShell module for use by a pipeline task

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?

like image 360
DenaliHardtail Avatar asked Dec 01 '25 09:12

DenaliHardtail


1 Answers

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. enter image description here

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).
like image 137
Lu Mike Avatar answered Dec 04 '25 00:12

Lu Mike



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!