1

I am using let's encrypt certificate and azure key vault to automate renewal process using this repo: https://github.com/brent-robinson/posh-acme-azure-example

I have installed the module Az.KeyVault using yaml on azure devops pipeline:

# Install the Az PowerShell modules our script will need
- task: PowerShell@2
  displayName: Install PowerShell Modules (Az.Accounts, Az.KeyVault, Az.Resources, Posh-ACME)
  inputs:
    targetType: 'inline'
    script: 'Install-Module Az.Accounts, Az.KeyVault, Az.Resources, Posh-ACME -Force'
    errorActionPreference: 'stop'
    failOnStderr: true
    pwsh: true

But, when I run the script, getting the below error:

The 'Get-AzKeyVaultCertificate' command was found in the
     | module 'Az.KeyVault', but the module could not be loaded. For
     | more information, run 'Import-Module Az.KeyVault'.

When I try to add the import module (Import-Module -Name Az.KeyVault -Force) it's giving the below error:

Assembly with the same name is already loaded
RNK
  • 5,582
  • 11
  • 65
  • 133
  • This means that there's an assembly version conflict, i.e. a different version of an assembly that the `Az.KeyVault` module is trying to load has already been loaded into the session. – mklement0 Sep 07 '22 at 21:39
  • @mklement0 how can I make it right? I didn't mention the version while installing the module so it should always install the latest one. right? What do you mean by assembly version? – RNK Sep 07 '22 at 21:53
  • The `Az.KeyVault` probably comes _bundled_ with the assemblies it needs. .NET assemblies are versioned (they have an embedded version number). PowerShell (Core) categorically prevents loading a _different_ version of a given assembly into a session - see [this answer](https://stackoverflow.com/a/72509967/45375). You'll need to find out which assembly/ies, specifically, cause the conflict (I have no simple answer). – mklement0 Sep 07 '22 at 22:15

2 Answers2

1

There is an issue with the latest version of Posh-ACME module (4.15.0). Install version 4.14.0 to resolve this.

Install-Module -Name Posh-ACME -RequiredVersion 4.14.0 -Force

Ref: https://github.com/brent-robinson/posh-acme-azure-example/issues/15#issuecomment-1241850416

RNK
  • 5,582
  • 11
  • 65
  • 133
  • Looks like they fixed it in version 4.15.1 https://www.powershellgallery.com/packages/Posh-ACME/4.15.1 – RNK Sep 12 '22 at 21:18
0

When you try to install the module in CI/CD pipeline you can specify the user so that it won't conflict with other.

#install Az PowerShell Modules with Specific User
- task: PowerShell@2
  displayName: Install PowerShell Modules (Az.Accounts, Az.KeyVault, Az.Resources, Posh-ACME)
  inputs:
    targetType: 'inline'
    script: 'Install-Module Az.Accounts, Az.KeyVault, Az.Resources, Posh-ACME -Force CurrentUser' 

The 'Get-AzKeyVaultCertificate' command was found in the | module 'Az.KeyVault', but the module could not be loaded. For | more information, run 'Import-Module Az.KeyVault'.

Assembly with the same name is already loaded

The error messages show that Az keyVault was already installed but not able to load in a pipeline to run task. You can specify the user(Current user or all user) to install the required module to specific user and import the required module.

Delliganesh Sevanesan
  • 4,146
  • 1
  • 5
  • 15