Search code examples
azure-keyvaultazure-cli

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?


Solution

  • 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