question

DaleGodfredson-2935 avatar image
0 Votes"
DaleGodfredson-2935 asked LeonLaude edited

Get Keyvault Access policies in Azure DevOps with Powershell

I'm attempting to run the following script as part of a DevOps pipeline to retrieve access policies from a Keyvault however it fails on the following command:

$keyVaultAccessPolicies = (Get-AzureRMKeyVault -VaultName $keyVaultName).accessPolicies

The error is: InvalidOperation: (:) [Get-AzureRmKeyVault], PSInvalidOperationException

Any help much appreciated.

Thanks

Full script is as follows:

 param(
    [string][parameter(Mandatory = $true)] $keyVaultName
 )
    
 $keyVaultAccessPolicies = (Get-AzureRMKeyVault -VaultName $keyVaultName).accessPolicies
 $armAccessPolicies = @()
    
 if($keyVaultAccessPolicies)
 {
    foreach($keyVaultAccessPolicy in $keyVaultAccessPolicies)
    {
       $armAccessPolicy = [pscustomobject]@{
          tenantId = $keyVaultAccessPolicy.TenantId
          objectId = $keyVaultAccessPolicy.ObjectId
       }
    
       $armAccessPolicyPermissions = [pscustomobject]@{
          keys = $keyVaultAccessPolicy.PermissionsToKeys
          secrets = $keyVaultAccessPolicy.PermissionsToSecrets
          certificates = $keyVaultAccessPolicy.PermissionsToCertificates
          storage = $keyVaultAccessPolicy.PermissionsToStorage
      }
    
      $armAccessPolicy | Add-Member -MemberType NoteProperty -Name permissions -Value $armAccessPolicyPermissions
    
      $armAccessPolicies += $armAccessPolicy
    }
 }
    
 $armAccessPoliciesParameter = [pscustomobject]@{
    list = $armAccessPolicies
 }
    
 $armAccessPoliciesParameter = $armAccessPoliciesParameter | ConvertTo-Json -Depth 5 -Compress
    
 Write-Host ("##vso[task.setvariable variable=Infra.KeyVault.AccessPolicies;]$armAccessPoliciesParameter")


not-supported
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

LeonLaude avatar image
0 Votes"
LeonLaude answered

Hi @DaleGodfredson-2935,

Please note that Azure DevOps is currently not supported in the Q&A forums, the supported products are listed over here https://docs.microsoft.com/en-us/answers/products.

You may ask the experts in the dedicated Azure DevOps forum over here:
https://developercommunity.visualstudio.com/report?space=21&entry=problem


(If the reply was helpful please don't forget to upvote and/or accept as answer, thank you)


Best regards,
Leon

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.