Skip to content

🐞 The 'Get-AzKeyVaultAccessPolicies' module could not be loaded. #445

Closed
@JoLanckriet

Description

@JoLanckriet

Hi,

Since a month ago retrieving keyvault access policies with arcus does not work anymore.

Using this step in the pipeline:

- task: AzurePowerShell@5
  displayName: 'Retrieve KeyVault Access Policies'
  inputs:
    azureSubscription: ${{parameters.azureSubscription}}
    scriptType: 'InlineScript'
    azurePowerShellVersion: 'LatestVersion'
    Inline: |
        Set-PSRepository -Name PSGallery -InstallationPolicy Trusted
        Install-Module -Name Arcus.Scripting.KeyVault -Repository PSGallery -AllowClobber
        $accessPolicies = Get-AzKeyVaultAccessPolicies -KeyVaultName $(InstallerApp.KeyVault.Name) -ResourceGroupName $(InstallerApp.ResourceGroup.Name)
        $accessPoliciesjson = $accessPolicies | ConvertTo-Json -Depth 5 -Compress
        Write-Host ("##vso[task.setvariable variable=InstallerApp.KeyVault.AccessPolicies;]$accessPoliciesjson")

This used to work like expected and the policies where retrieved however the following error started appearing since the middle of december 2024 (to my knowledge).

##[error]The 'Get-AzKeyVaultAccessPolicies' command was found in the module 'Arcus.Scripting.KeyVault', but the module could not be loaded. For more information, run 'Import-Module Arcus.Scripting.KeyVault'.
##[error]PowerShell exited with code '1'.

I was able to resolve this by installing the Az.Accounts module seperately in the pipeline before executing the step mentioned above. This results in the following steps:

- task: AzurePowerShell@5
  displayName: 'Install Az.Accounts'
  inputs:
    azureSubscription: ${{parameters.azureSubscription}}
    scriptType: 'InlineScript'
    azurePowerShellVersion: 'LatestVersion'
    Inline: |    
        Get-InstalledModule -Name Az.Accounts -AllVersions -ErrorAction SilentlyContinue | Uninstall-Module -Force -ErrorAction SilentlyContinue
        Install-Module -Name Az.Accounts -Force -AllowClobber

- task: AzurePowerShell@5
  displayName: 'Retrieve KeyVault Access Policies'
  inputs:
    azureSubscription: ${{parameters.azureSubscription}}
    scriptType: 'InlineScript'
    azurePowerShellVersion: 'LatestVersion'
    Inline: |
        Set-PSRepository -Name PSGallery -InstallationPolicy Trusted
        Install-Module -Name Arcus.Scripting.KeyVault -Repository PSGallery -AllowClobber
        $accessPolicies = Get-AzKeyVaultAccessPolicies -KeyVaultName $(InstallerApp.KeyVault.Name) -ResourceGroupName $(InstallerApp.ResourceGroup.Name)
        $accessPoliciesjson = $accessPolicies | ConvertTo-Json -Depth 5 -Compress
        Write-Host ("##vso[task.setvariable variable=InstallerApp.KeyVault.AccessPolicies;]$accessPoliciesjson")

Doing this returns the expected behaviour.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:key-vaultAll issues related to Azure Key VaultbugSomething isn't workingdependenciesPull requests that update a dependency file

    Type

    No type

    Projects

    Status

    Done

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions