Azure Key Vault: List Certificates with Pagination
See more Azure Key Vault Examples
Requires Chilkat 11.6.0 or later. Keep qa_data/azure/keyvault.json and token/PFX files private, outside web content and source control, with access restricted to the application identity. Use placeholders replaced by your configuration, never commit credentials. Create output directories before running file-writing examples. These examples target Azure public-cloud vaults, not Managed HSM or sovereign-cloud endpoints.
Uses HTTPS and Key Vault data-plane API 2026-04-01. Configure vault_name and first run the client-credentials token example. It writes access_token and an expires_at UTC timestamp to qa_data/tokens/azureKeyVaultToken.json. Each request checks expiration; refresh is explicit. The sample stops on errors and does not retry. Production callers should handle 429/Retry-After and transient failures with bounded backoff, and reconcile uncertain writes. Redirects are disabled.
Lists certificate identities and latest-version metadata, following every non-null nextLink, including after empty pages. This does not list historical versions or download certificates. Requests 25 entries per page, checks for cycles, and permits only the original vault and certificate-list path before forwarding the bearer token. Requires certificates/list. Enumeration is not a snapshot; concurrent updates can change results.
Chilkat PowerShell Downloads
Add-Type -Path "C:\chilkat\ChilkatDotNet47-x64\ChilkatDotNet47.dll"
$success = $false
$stringCompare = New-Object Chilkat.StringBuilder
# Assumes Chilkat is unlocked. See Global Unlock Sample.
# Keep this configuration private, outside public web content and source control.
$config = New-Object Chilkat.JsonObject
$config.Strict = $true
$success = $config.LoadFile("qa_data/azure/keyvault.json")
if ($success -ne $true) {
$("Could not load private Key Vault configuration.")
exit
}
$stringCompare.SetString($config.StringOf("vault_name"))
$stringMatch1 = $stringCompare.ContentsEqual("",$true)
if (($config.JsonTypeOf("vault_name") -ne 1) -or ($stringMatch1 -eq $true)) {
$("Missing or invalid vault_name.")
exit
}
$validate1 = New-Object Chilkat.StringBuilder
$alphabet1 = New-Object Chilkat.StringBuilder
$success = $validate1.Append($config.StringOf("vault_name"))
if ($success -ne $true) {
$("Could not validate vault_name.")
exit
}
$success = $alphabet1.Append("abcdefghijklmnopqrstuvwxyz0123456789-")
if ($success -ne $true) {
$("Could not initialize validation.")
exit
}
if (($validate1.Length -lt 3) -or ($validate1.Length -gt 24)) {
$("Invalid vault_name length.")
exit
}
$charIndex1 = 0
while (($charIndex1 -lt $validate1.Length)) {
if ($alphabet1.Contains($validate1.GetRange($charIndex1,1,$false),$true) -ne $true) {
$("Invalid character in vault_name.")
exit
}
$charIndex1 = $charIndex1 + 1
}
$vaultName = New-Object Chilkat.StringBuilder
$vaultName.Append($config.StringOf("vault_name"))
$letters = New-Object Chilkat.StringBuilder
$letters.Append("abcdefghijklmnopqrstuvwxyz")
if (($letters.Contains($vaultName.GetRange(0,1,$false),$true) -ne $true) -or ($vaultName.EndsWith("-",$true) -eq $true) -or ($vaultName.Contains("--",$true) -eq $true)) {
$("Invalid vault_name.")
exit
}
$origin = New-Object Chilkat.StringBuilder
$success = $origin.Append("https://")
if ($success -ne $true) {
$("Could not construct URL or identifier.")
exit
}
$success = $origin.Append($config.StringOf("vault_name"))
if ($success -ne $true) {
$("Could not construct URL or identifier.")
exit
}
$success = $origin.Append(".vault.azure.net")
if ($success -ne $true) {
$("Could not construct URL or identifier.")
exit
}
$http = New-Object Chilkat.Http
$http.RequireSslCertVerify = $true
$http.FollowRedirects = $false
$http.ConnectTimeout = 20
$http.ReadTimeout = 60
$http.VerboseLogging = $false
$request = New-Object Chilkat.HttpRequest
$request.HttpVerb = "GET"
$response = New-Object Chilkat.HttpResponse
$result = New-Object Chilkat.JsonObject
$result.Strict = $true
# First run Get a Key Vault access token.
$token = New-Object Chilkat.JsonObject
$token.Strict = $true
$success = $token.LoadFile("qa_data/tokens/azureKeyVaultToken.json")
if ($success -ne $true) {
$("Could not read the private token file.")
exit
}
$stringCompare.SetString($token.StringOf("access_token"))
$stringMatch2 = $stringCompare.ContentsEqual("",$true)
if (($token.JsonTypeOf("access_token") -ne 1) -or ($stringMatch2 -eq $true)) {
$("Missing or invalid access_token.")
exit
}
$stringCompare.SetString($token.StringOf("expires_at"))
$stringMatch3 = $stringCompare.ContentsEqual("",$true)
if (($token.JsonTypeOf("expires_at") -ne 1) -or ($stringMatch3 -eq $true)) {
$("Missing or invalid expires_at.")
exit
}
$expires = New-Object Chilkat.CkDateTime
$now = New-Object Chilkat.CkDateTime
$success = $expires.SetFromTimestamp($token.StringOf("expires_at"))
if ($success -ne $true) {
$("Invalid token expiration.")
exit
}
$http.AuthToken = $token.StringOf("access_token")
$certPrefix = New-Object Chilkat.StringBuilder
$success = $certPrefix.Append($origin.GetAsString())
if ($success -ne $true) {
$("Could not construct URL or identifier.")
exit
}
$success = $certPrefix.Append("/certificates/")
if ($success -ne $true) {
$("Could not construct URL or identifier.")
exit
}
$listPrefix = New-Object Chilkat.StringBuilder
$success = $listPrefix.Append($origin.GetAsString())
if ($success -ne $true) {
$("Could not construct URL or identifier.")
exit
}
$success = $listPrefix.Append("/certificates?")
if ($success -ne $true) {
$("Could not construct URL or identifier.")
exit
}
$listUrl = New-Object Chilkat.StringBuilder
$success = $listUrl.Append($listPrefix.GetAsString())
if ($success -ne $true) {
$("Could not construct URL or identifier.")
exit
}
$success = $listUrl.Append("api-version=2026-04-01&maxresults=25")
if ($success -ne $true) {
$("Could not construct URL or identifier.")
exit
}
$listSeen = New-Object Chilkat.Hashtable
$listItems = New-Object Chilkat.JsonArray
$listView = New-Object Chilkat.JsonArray
$listEntry = New-Object Chilkat.JsonObject
$listCurrentUrl = $listUrl.GetAsString()
$listPages = 0
$listMore = $true
while (($listMore -eq $true)) {
if ($listPages -eq 10000) {
$("Page bound reached; enumeration is incomplete.")
exit
}
if ($listSeen.Contains($listCurrentUrl) -eq $true) {
$("Repeated nextLink; enumeration is incomplete.")
exit
}
$success = $listSeen.AddStr($listCurrentUrl,"seen")
if ($success -ne $true) {
$("Could not track pagination.")
exit
}
$listPages = $listPages + 1
$success = $now.SetFromCurrentSystemTime()
if ($success -ne $true) {
$("Could not read current time.")
exit
}
if ($expires.DiffSeconds($now) -le 60) {
$("Token is expired or near expiration. Obtain a new token before continuing.")
exit
}
$success = $http.HttpReq($listCurrentUrl,$request,$response)
if ($success -ne $true) {
$("Request did not complete; inspect diagnostics privately.")
exit
}
if ($response.StatusCode -ne 200) {
$("HTTP status: " + $response.StatusCode)
$("Request ID: " + $response.GetHeaderField("x-ms-request-id"))
# Do not print full response bodies, tokens, or diagnostic logs.
$("Request failed. Inspect private diagnostics; reconcile writes before retrying.")
exit
}
$success = $result.Load($response.BodyStr)
if ($success -ne $true) {
$("Expected a well-formed JSON response.")
exit
}
if ($result.JsonTypeOf("value") -ne 4) {
$("Expected a value array.")
exit
}
$success = $result.ArrayOf2("value",$listView)
if ($success -ne $true) {
$("Could not read certificate array.")
exit
}
$success = $listItems.Load($listView.Emit())
if ($success -ne $true) {
$("Could not detach the page before nested requests.")
exit
}
$listMore = $false
if ($result.HasMember("nextLink") -eq $true) {
if ($result.JsonTypeOf("nextLink") -ne 6) {
$stringCompare.SetString($result.StringOf("nextLink"))
$stringMatch4 = $stringCompare.ContentsEqual("",$true)
if (($result.JsonTypeOf("nextLink") -ne 1) -or ($stringMatch4 -eq $true)) {
$("Missing or invalid nextLink.")
exit
}
$listCurrentUrl = $result.StringOf("nextLink")
$listNext = New-Object Chilkat.StringBuilder
$success = $listNext.Append($listCurrentUrl)
if ($success -ne $true) {
$("Could not construct URL or identifier.")
exit
}
if (($listNext.StartsWith($listPrefix.GetAsString(),$true) -ne $true) -or ($listNext.Contains("#",$true) -eq $true) -or ($listNext.Contains("\",$true) -eq $true) -or ($listNext.Contains("`r",$true) -eq $true) -or ($listNext.Contains("`n",$true) -eq $true)) {
$("Unsafe pagination URL; stopped before sending a token.")
exit
}
$listMore = $true
}
}
$listIndex = 0
while (($listIndex -lt $listItems.Size)) {
$success = $listItems.ObjectAt2($listIndex,$listEntry)
if ($success -ne $true) {
$("Expected a certificate object.")
exit
}
$stringCompare.SetString($listEntry.StringOf("id"))
$stringMatch5 = $stringCompare.ContentsEqual("",$true)
if (($listEntry.JsonTypeOf("id") -ne 1) -or ($stringMatch5 -eq $true)) {
$("Missing or invalid id.")
exit
}
$listedNameId = New-Object Chilkat.StringBuilder
$success = $listedNameId.Append($listEntry.StringOf("id"))
if ($success -ne $true) {
$("Could not construct URL or identifier.")
exit
}
if ($listedNameId.StartsWith($certPrefix.GetAsString(),$true) -ne $true) {
$("Returned identifier is outside the expected vault/resource.")
exit
}
$listedName = $listedNameId.GetRange($certPrefix.Length,$listedNameId.Length - $certPrefix.Length,$false)
$validate6 = New-Object Chilkat.StringBuilder
$alphabet6 = New-Object Chilkat.StringBuilder
$success = $validate6.Append($listedName)
if ($success -ne $true) {
$("Could not validate resource identifier.")
exit
}
$success = $alphabet6.Append("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-")
if ($success -ne $true) {
$("Could not initialize validation.")
exit
}
if (($validate6.Length -lt 1) -or ($validate6.Length -gt 127)) {
$("Invalid resource identifier length.")
exit
}
$charIndex6 = 0
while (($charIndex6 -lt $validate6.Length)) {
if ($alphabet6.Contains($validate6.GetRange($charIndex6,1,$false),$true) -ne $true) {
$("Invalid character in resource identifier.")
exit
}
$charIndex6 = $charIndex6 + 1
}
$("Certificate ID: " + $listEntry.StringOf("id"))
if ($listEntry.JsonTypeOf("attributes.enabled") -eq 5) {
$("Enabled: " + $listEntry.BoolOf("attributes.enabled"))
}
# Attributes are optional; preserve Unix-time values as strings (not 32-bit integers).
if ($listEntry.JsonTypeOf("attributes.exp") -eq 2) {
$("Expires (Unix seconds): " + $listEntry.StringOf("attributes.exp"))
}
$listIndex = $listIndex + 1
}
}
$("Certificate enumeration complete.")