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

Azure Storage Accounts: List Accounts in a Subscription

See more Azure Storage Accounts Examples

Lists storage accounts in a subscription using the Storage Resource Provider API, version 2026-09-01. Displays each account's name, string resource ID, location, SKU, provisioning state, and available blob endpoint. No account keys are returned.

Replace the all-zero subscription ID. The identity needs Microsoft.Storage/storageAccounts/read across the subscription (for example, the Reader role there). The code follows each opaque nextLink, including after an empty page, and stops on malformed responses, repeated links, or a page limit. Partial output is not reported as a complete inventory. Continuation URLs are checked before sending the bearer token; redirects are disabled.

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 VBScript Downloads

VBScript
Dim fso, outFile
Set fso = CreateObject("Scripting.FileSystemObject")
'Create a Unicode (utf-16) output text file.
Set outFile = fso.CreateTextFile("output.txt", True, True)

success = 0

set stringCompare = CreateObject("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.
set token = CreateObject("Chilkat.JsonObject")
token.Strict = 1
success = token.LoadFile("qa_data/tokens/azureToken.json")
If (success <> 1) Then
    outFile.WriteLine("Could not load the private Azure Resource Manager token file.")
    WScript.Quit
End If

If ((token.JsonTypeOf("access_token") <> 1) Or (token.StringOfEquals("access_token","",1) = 1)) Then
    outFile.WriteLine("A nonempty access_token string is required.")
    WScript.Quit
End If

'  Use your subscription ID as a string. The all-zero value is only a placeholder.
subscriptionId = "00000000-0000-0000-0000-000000000000"
set http = CreateObject("Chilkat.Http")
http.AuthToken = token.StringOf("access_token")
http.Accept = "application/json"
http.RequireSslCertVerify = 1
http.FollowRedirects = 0
http.ConnectTimeout = 30
http.ReadTimeout = 60
success = http.SetUrlVar("subscriptionId",subscriptionId)
If (success <> 1) Then
    outFile.WriteLine("Could not encode subscription ID.")
    WScript.Quit
End If

set response = CreateObject("Chilkat.HttpResponse")
set result = CreateObject("Chilkat.JsonObject")
result.Strict = 1
set parsed = CreateObject("Chilkat.Url")

'  Http substitutes and URL-encodes {$subscriptionId} in this first request.
requestUrl = "https://management.azure.com/subscriptions/{$subscriptionId}/providers/Microsoft.Storage/storageAccounts?api-version=2026-09-01"
set seen = CreateObject("Chilkat.Hashtable")
set accounts = CreateObject("Chilkat.JsonArray")
set account = CreateObject("Chilkat.JsonObject")
morePages = 1
page = 0
total = 0
Do While (morePages = 1)
    '  A limit and a repeated-link check protect against an endless continuation loop.
    If (page >= 1000) Then
        outFile.WriteLine("Page limit reached. Listing is incomplete; resume from: " & requestUrl)
        WScript.Quit
    End If

    If (seen.Contains(requestUrl) = 1) Then
        outFile.WriteLine("Repeated continuation URL; listing is incomplete.")
        WScript.Quit
    End If

    success = seen.AddStr(requestUrl,"seen")
    If (success <> 1) Then
        outFile.WriteLine("Could not record the continuation URL.")
        WScript.Quit
    End If

    success = http.HttpNoBody("GET",requestUrl,response)
    If (response.StatusCode = 0) Then
        outFile.WriteLine("No HTTP response. Inspect LastErrorText privately; it may contain credentials.")
        WScript.Quit
    End If

    If ((response.StatusCode <> 200)) Then
        outFile.WriteLine("HTTP status: " & response.StatusCode)
        outFile.WriteLine("Request ID: " & response.GetHeaderField("x-ms-request-id"))
        outFile.WriteLine("Retry-After: " & response.GetHeaderField("Retry-After"))
        '  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.
        WScript.Quit
    End If

    If (success <> 1) Then
        outFile.WriteLine("The HTTP response could not be read completely.")
        WScript.Quit
    End If

    success = result.Load(response.BodyStr)
    If (success <> 1) Then
        outFile.WriteLine("Expected a well-formed JSON response.")
        WScript.Quit
    End If

    If (result.JsonTypeOf("value") <> 4) Then
        outFile.WriteLine("Expected a value array of storage accounts.")
        WScript.Quit
    End If

    success = result.ArrayOf2("value",accounts)
    If (success <> 1) Then
        outFile.WriteLine("Could not read the storage account array.")
        WScript.Quit
    End If

    i = 0
    Do While (i < accounts.Size)
        success = accounts.ObjectAt2(i,account)
        If (success <> 1) Then
            outFile.WriteLine("Invalid storage account entry.")
            WScript.Quit
        End If

        If ((account.JsonTypeOf("id") <> 1) Or (account.JsonTypeOf("name") <> 1)) Then
            outFile.WriteLine("Expected a storage account ID and name.")
            WScript.Quit
        End If

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

        total = total + 1
        i = i + 1
    Loop
    page = page + 1
    morePages = 0
    If (result.HasMember("nextLink") = 1) Then
        If ((result.IsNullOf("nextLink") <> 1) And (result.JsonTypeOf("nextLink") <> 1)) Then
            outFile.WriteLine("Invalid nextLink; listing is incomplete.")
            WScript.Quit
        End If

        If ((result.JsonTypeOf("nextLink") = 1) And (result.StringOfEquals("nextLink","",1) <> 1)) Then
            requestUrl = result.StringOf("nextLink")
            success = parsed.ParseUrl(requestUrl)
            If (success <> 1) Then
                outFile.WriteLine("Missing or invalid continuation URL.")
                WScript.Quit
            End If

            success = stringCompare.SetString(parsed.Scheme)
            stringMatch1 = stringCompare.ContentsEqual("https",1)
            success = stringCompare.SetString(parsed.Host)
            stringMatch2 = stringCompare.ContentsEqual("management.azure.com",1)
            success = stringCompare.SetString(parsed.Login)
            stringMatch3 = stringCompare.ContentsEqual("",1)
            success = stringCompare.SetString(parsed.Password)
            stringMatch4 = stringCompare.ContentsEqual("",1)
            success = stringCompare.SetString(parsed.Frag)
            stringMatch5 = stringCompare.ContentsEqual("",1)
            If ((stringMatch1 <> 1) Or (stringMatch2 <> 1) Or (parsed.Port <> 443) Or (stringMatch3 <> 1) Or (stringMatch4 <> 1) Or (stringMatch5 <> 1)) Then
                outFile.WriteLine("Unexpected continuation URL; refusing to send the access token.")
                WScript.Quit
            End If

            '  The server owns nextLink. Keep its query intact; do not add api-version.
            '  Continue even if the current page contained no accounts.
            morePages = 1
        End If

    End If

Loop
outFile.WriteLine("Listing complete. Storage accounts: " & total)

outFile.Close