Sample code for 30+ languages & platforms
AutoIt Requires Chilkat v11.6.0+

Azure Storage Accounts: List Storage Accounts in a Resource Group

See more Azure Storage Accounts Examples

Lists accounts in one existing resource group. Requires account read permission at the appropriate scope. Follows opaque continuation URLs without rewriting their query strings and handles empty pages, repeated links, and incomplete results. Resource IDs remain strings; no account keys are requested.

These calls manage Azure resources at management.azure.com. They do not upload or download stored data. Supply a current Microsoft Entra access token for Azure Resource Manager in private qa_data/tokens/azureToken.json, with a nonempty access_token string. For v2 client credentials, request https://management.azure.com/.default; obtain a new token when it expires. A storage account key, SAS, Microsoft Graph token, or Storage data-plane token is not an ARM token. Never print the token or commit its file.

Azure RBAC must grant the caller the required management actions at the appropriate scope. An app registration alone does not grant resource access. Management permissions and blob/file data permissions are distinct. These examples target public Azure; sovereign clouds require the corresponding authority, ARM endpoint, token audience, and continuation-host validation.

Microsoft API reference

Chilkat AutoIt Downloads

AutoIt
Local $bSuccess = False

$oStringCompare = ObjCreate("Chilkat.StringBuilder")
;  This example requires the Chilkat API to have been previously unlocked.
;  See Global.UnlockBundle for sample code.

;  This is Azure Resource Manager (the management plane), not a blob data request.
;  Load an unexpired Microsoft Entra token whose audience is Azure Resource Manager.
;  For the v2 token endpoint, request scope https://management.azure.com/.default.
;  Keep the token file private and out of source control and public web directories.
$oToken = ObjCreate("Chilkat.JsonObject")
$oToken.Strict = True
$bSuccess = $oToken.LoadFile("qa_data/tokens/azureToken.json")
If ($bSuccess <> True) Then
    ConsoleWrite("Could not load the private Azure Resource Manager token file." & @CRLF)
    Exit
EndIf

If (($oToken.JsonTypeOf("access_token") <> 1) Or ($oToken.StringOfEquals("access_token","",True) = True)) Then
    ConsoleWrite("A nonempty access_token string is required." & @CRLF)
    Exit
EndIf

;  Use your subscription ID as a string. The all-zero value is only a placeholder.
Local $subscriptionId = "00000000-0000-0000-0000-000000000000"
$oHttp = ObjCreate("Chilkat.Http")
$oHttp.AuthToken = $oToken.StringOf("access_token")
$oHttp.Accept = "application/json"
$oHttp.RequireSslCertVerify = True
$oHttp.FollowRedirects = False
$oHttp.ConnectTimeout = 30
$oHttp.ReadTimeout = 60
$bSuccess = $oHttp.SetUrlVar("subscriptionId",$subscriptionId)
If ($bSuccess <> True) Then
    ConsoleWrite("Could not encode subscription ID." & @CRLF)
    Exit
EndIf

$oResponse = ObjCreate("Chilkat.HttpResponse")
$oResult = ObjCreate("Chilkat.JsonObject")
$oResult.Strict = True
$oParsed = ObjCreate("Chilkat.Url")
Local $sResourceGroupName = "my-resource-group"
$bSuccess = $oHttp.SetUrlVar("resourceGroupName",$sResourceGroupName)
If ($bSuccess <> True) Then
    ConsoleWrite("Could not encode resource group." & @CRLF)
    Exit
EndIf

;  Http substitutes and URL-encodes {$subscriptionId} in this first request.
Local $sRequestUrl = "https://management.azure.com/subscriptions/{$subscriptionId}/resourceGroups/{$resourceGroupName}/providers/Microsoft.Storage/storageAccounts?api-version=2026-09-01"
$oSeen = ObjCreate("Chilkat.Hashtable")
$oAccounts = ObjCreate("Chilkat.JsonArray")
$oAccount = ObjCreate("Chilkat.JsonObject")
Local $bMorePages = True
Local $iPage = 0
Local $iTotal = 0
While ($bMorePages = True)
    ;  A limit and a repeated-link check protect against an endless continuation loop.
    If ($iPage >= 1000) Then
        ConsoleWrite("Page limit reached. Listing is incomplete; resume from: " & $sRequestUrl & @CRLF)
        Exit
    EndIf

    If ($oSeen.Contains($sRequestUrl) = True) Then
        ConsoleWrite("Repeated continuation URL; listing is incomplete." & @CRLF)
        Exit
    EndIf

    $bSuccess = $oSeen.AddStr($sRequestUrl,"seen")
    If ($bSuccess <> True) Then
        ConsoleWrite("Could not record the continuation URL." & @CRLF)
        Exit
    EndIf

    $bSuccess = $oHttp.HttpNoBody("GET",$sRequestUrl,$oResponse)
    If ($oResponse.StatusCode = 0) Then
        ConsoleWrite("No HTTP response. Inspect LastErrorText privately; it may contain credentials." & @CRLF)
        Exit
    EndIf

    If (($oResponse.StatusCode <> 200)) Then
        ConsoleWrite("HTTP status: " & $oResponse.StatusCode & @CRLF)
        ConsoleWrite("Request ID: " & $oResponse.GetHeaderField("x-ms-request-id") & @CRLF)
        ConsoleWrite("Retry-After: " & $oResponse.GetHeaderField("Retry-After") & @CRLF)
        ;  Inspect the error body privately. Do not log tokens, headers, or full responses.
        ;  For 401 check the token/audience; for 403 check Azure RBAC and policy.
        ;  Honor Retry-After for 429 and use bounded backoff for transient failures.
        Exit
    EndIf

    If ($bSuccess <> True) Then
        ConsoleWrite("The HTTP response could not be read completely." & @CRLF)
        Exit
    EndIf

    $bSuccess = $oResult.Load($oResponse.BodyStr)
    If ($bSuccess <> True) Then
        ConsoleWrite("Expected a well-formed JSON response." & @CRLF)
        Exit
    EndIf

    If ($oResult.JsonTypeOf("value") <> 4) Then
        ConsoleWrite("Expected a value array of storage accounts." & @CRLF)
        Exit
    EndIf

    $bSuccess = $oResult.ArrayOf2("value",$oAccounts)
    If ($bSuccess <> True) Then
        ConsoleWrite("Could not read the storage account array." & @CRLF)
        Exit
    EndIf

Local $i = 0
    While ($i < $oAccounts.Size)
        $bSuccess = $oAccounts.ObjectAt2($i,$oAccount)
        If ($bSuccess <> True) Then
            ConsoleWrite("Invalid storage account entry." & @CRLF)
            Exit
        EndIf

        If (($oAccount.JsonTypeOf("id") <> 1) Or ($oAccount.JsonTypeOf("name") <> 1)) Then
            ConsoleWrite("Expected a storage account ID and name." & @CRLF)
            Exit
        EndIf

        ;  ARM resource IDs are strings, not numbers. Save id for later management calls.
        ConsoleWrite("Name: " & $oAccount.StringOf("name") & @CRLF)
        ConsoleWrite("Resource ID: " & $oAccount.StringOf("id") & @CRLF)
        ConsoleWrite("Location: " & $oAccount.StringOf("location") & @CRLF)
        ConsoleWrite("Kind: " & $oAccount.StringOf("kind") & @CRLF)
        ConsoleWrite("SKU: " & $oAccount.StringOf("sku.name") & @CRLF)
        ConsoleWrite("Provisioning state: " & $oAccount.StringOf("properties.provisioningState") & @CRLF)
        ;  Endpoint availability depends on account kind and provisioning state.
        If ($oAccount.JsonTypeOf("properties.primaryEndpoints.blob") = 1) Then
            ConsoleWrite("Blob endpoint: " & $oAccount.StringOf("properties.primaryEndpoints.blob") & @CRLF)
        EndIf

        $iTotal = $iTotal + 1
        $i = $i + 1
    Wend
    $iPage = $iPage + 1
    $bMorePages = False
    If ($oResult.HasMember("nextLink") = True) Then
        If (($oResult.IsNullOf("nextLink") <> True) And ($oResult.JsonTypeOf("nextLink") <> 1)) Then
            ConsoleWrite("Invalid nextLink; listing is incomplete." & @CRLF)
            Exit
        EndIf

        If (($oResult.JsonTypeOf("nextLink") = 1) And ($oResult.StringOfEquals("nextLink","",True) <> True)) Then
            $sRequestUrl = $oResult.StringOf("nextLink")
            $bSuccess = $oParsed.ParseUrl($sRequestUrl)
            If ($bSuccess <> True) Then
                ConsoleWrite("Missing or invalid continuation URL." & @CRLF)
                Exit
            EndIf

            $oStringCompare.SetString($oParsed.Scheme)
Local $bStringMatch1 = $oStringCompare.ContentsEqual("https",True)
            $oStringCompare.SetString($oParsed.Host)
Local $bStringMatch2 = $oStringCompare.ContentsEqual("management.azure.com",True)
            $oStringCompare.SetString($oParsed.Login)
Local $bStringMatch3 = $oStringCompare.ContentsEqual("",True)
            $oStringCompare.SetString($oParsed.Password)
Local $bStringMatch4 = $oStringCompare.ContentsEqual("",True)
            $oStringCompare.SetString($oParsed.Frag)
Local $bStringMatch5 = $oStringCompare.ContentsEqual("",True)
            If (($bStringMatch1 <> True) Or ($bStringMatch2 <> True) Or ($oParsed.Port <> 443) Or ($bStringMatch3 <> True) Or ($bStringMatch4 <> True) Or ($bStringMatch5 <> True)) Then
                ConsoleWrite("Unexpected continuation URL; refusing to send the access token." & @CRLF)
                Exit
            EndIf

            ;  The server owns nextLink. Keep its query intact; do not add api-version.
            ;  Continue even if the current page contained no accounts.
            $bMorePages = True
        EndIf

    EndIf

Wend
ConsoleWrite("Listing complete. Storage accounts: " & $iTotal & @CRLF)