Created
July 24, 2023 18:27
-
-
Save JayDoubleu/e702fba0ae8560d036d5ab174191132e to your computer and use it in GitHub Desktop.
List storage keys by authenticating via managed identity
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$url = 'http://169.254.169.254/metadata/identity/oauth2/token?api-version=2018-02-01&resource=https://management.azure.com/' | |
$accessToken = Invoke-RestMethod -Uri $url -Headers @{Metadata = 'true'} -Method Get -UseBasicParsing | Select-Object -ExpandProperty access_token | |
Write-Host "Access token: $accessToken" | |
$storageAccountResourceId = '/subscriptions/1c0c1a70-a036-40b3-a022-77db654391c4/resourceGroups/rg-kns-testing-prd-a-uks-01/providers/Microsoft.Storage/storageAccounts/stgknstestingprdauks01' | |
$url = 'https://management.azure.com/'+ $storageAccountResourceId + '/listKeys?api-version=2022-09-01&$expand=kerb' | |
$headers = @{ | |
'Accept' = 'application/json' | |
'Authorization' = 'Bearer ' + $accessToken | |
} | |
$body = '' | |
$response = Invoke-RestMethod -Uri $url -Headers $headers -Method POST -Body $body |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment