Dr Schizo
Dr Schizo

Reputation: 4362

Get KeyVault Get Access Policies via Powershell AZ CLI

I am trying to read in the access policies using the az cmdlets but struggling to do this. I thought this would work

$foo = az keyvault show -g "my-rg" -n "my-kv" 

This returns a value back and was hoping to do:

$accessPolicies = $foo.accessPolicies

However this returns a null. I did notice the output produces properties so I also tried

$accessPolicies = $foo.properties.accessPolicies

Clearly doing something wrong here. Any ideas how I do this?

Upvotes: 1

Views: 1368

Answers (1)

Nancy Xiong
Nancy Xiong

Reputation: 28224

You could directly query the accessPolicies properties from the Azure CLI command.

$accessPolicies = az keyvault show -g "my-rg" -n "my-kv" --query 'properties.accessPolicies'

The --query parameter needs the JMESPath query string. See http://jmespath.org/ for more information and examples.

If you want to use the PowerShell commands, you can do it like this:

$accessPolicies= (Get-AzKeyVault -vaultname "my-kv" -resourcegroupname "my-rg").AccessPolicies

Upvotes: 1

Related Questions