Last active
February 22, 2021 14:39
-
-
Save rndazurescript/bcdf195f9a8e7b0bf80d9e8882713b9f to your computer and use it in GitHub Desktop.
Access storage account using managed identity on a VM
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
$stgaccount="ctenteststg" | |
$uri="http://169.254.169.254/metadata/identity/oauth2/token?api-version=2018-02-01&resource=https://"+$stgaccount+".blob.core.windows.net" | |
$token=Invoke-RestMethod -Method GET -Uri $uri -Headers @{"Metadata"="True"} | |
$listContentUrl="https://"+$stgaccount+".blob.core.windows.net/testdata" | |
$Parameters = @{ | |
restype = 'container' | |
comp = 'list' | |
} | |
$result=Invoke-RestMethod -Method GET -Uri $listContentUrl -Headers @{"Authorization"="Bearer " + $token.access_token; "x-ms-version"="2017-11-09"} -Body $Parameters | |
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
$stgaccount="ctenteststg" | |
$uri="http://169.254.169.254/metadata/identity/oauth2/token?api-version=2018-02-01&resource=https://"+$stgaccount+".dfs.core.windows.net" | |
$token=Invoke-RestMethod -Method GET -Uri $uri -Headers @{"Metadata"="True"} | |
# REST API DOCS | |
# https://docs.microsoft.com/en-us/rest/api/storageservices/datalakestoragegen2/path/list | |
$listContentUrl="https://"+$stgaccount+".dfs.core.windows.net/testdata" | |
$Parameters = @{ | |
recursive = 'true'; | |
resource = 'filesystem' | |
} | |
$headers = @{ | |
"Authorization"="Bearer " + $token.access_token; | |
} | |
$result=Invoke-RestMethod -Method GET -Uri $listContentUrl -Headers $headers -Body $Parameters | |
$result | ConvertTo-Json |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment