Claus Appel
Claus Appel

Reputation: 1565

How to get more than the first 25 secrets from an Azure key vault via command line?

I am using az keyvault secret list to get secrets from my Azure key vault. Its help says:

Arguments
    --maxresults                    : Maximum number of results to return in a page. If not
                                      specified, the service will return up to 25 results.

It is not possible to set --maxresults any higher than 25. The help says "in a page", but I can find no explanation of how to get the next page.

Is it possible to list more than the top 25 secrets using this tool?

Upvotes: 4

Views: 1946

Answers (2)

Ibene Liz Mathew
Ibene Liz Mathew

Reputation: 53

To get all the secrets with name and value via azure cli in Mac, you can use the below script:
sh keyvault-list.sh keyvaultname

#!/usr/bin/env bash

keyvaultEntries=($(az keyvault secret list --vault-name $1 --query "[*].{name:name}" -o tsv))

for i in "${keyvaultEntries[@]}"
do
    # do whatever on "$i" here
    echo "$i"::"$(az keyvault secret show --name $i --vault-name $1 -o tsv --query value)"
done

Upvotes: 1

Delliganesh Sevanesan
Delliganesh Sevanesan

Reputation: 4776

We cannot get more than 25 Secret lists by using the --maxresults in the CLI command.

Please find the below workaround:

If we specify the --maxresults more than 25 the cli returns the below result.

Az keyvault secret list --vault-name <your keyvault name> --maxresults 30

enter image description here

If you want to get all the Secrets in a specific key vault you have to use the below command without using --maxresults.

Az keyvault secret list --vault-name <your keyvault name>

enter image description here

Or If you want it to achieve programmatically need to write a script with the REST API or some language library directly. Refer here

Upvotes: 3

Related Questions