Forked from jamiekt/CreateAzureBLOBusingPowershell
Last active
September 16, 2019 21:43
-
-
Save Hugoberry/383c98e5f0a27e3a80d0fff78e347eeb to your computer and use it in GitHub Desktop.
List Azure File Shared Storage using the REST API and Powershell
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
$method = "GET" | |
$headerDate = '2017-04-17' | |
$headers = @{"x-ms-version"="$headerDate"} | |
$StorageAccountName = "<your account name>" | |
$StorageAccountKey = "<your account key>" | |
$Url = "https://$StorageAccountName.file.core.windows.net/?comp=list" | |
$xmsdate = (get-date -format r).ToString() | |
$headers.Add("x-ms-date",$xmsdate) | |
$signatureString = "$method$([char]10)$([char]10)$([char]10)$contentLength$([char]10)$([char]10)$([char]10)$([char]10)$([char]10)$([char]10)$([char]10)$([char]10)$([char]10)" | |
#Add CanonicalizedHeaders | |
$signatureString += "x-ms-date:" + $headers["x-ms-date"] + "$([char]10)" | |
$signatureString += "x-ms-version:" + $headers["x-ms-version"] + "$([char]10)" | |
#Add CanonicalizedResource | |
$uri = New-Object System.Uri -ArgumentList $url | |
$signatureString += "/" + $StorageAccountName + $uri.AbsolutePath | |
$dataToMac = [System.Text.Encoding]::UTF8.GetBytes($signatureString) | |
$accountKeyBytes = [System.Convert]::FromBase64String($StorageAccountKey) | |
$hmac = new-object System.Security.Cryptography.HMACSHA256((,$accountKeyBytes)) | |
$signature = [System.Convert]::ToBase64String($hmac.ComputeHash($dataToMac)) | |
$headers.Add("Authorization", "SharedKey " + $StorageAccountName + ":" + $signature); | |
write-host -fore green $signatureString | |
Invoke-RestMethod -Uri $Url -Method $method -headers $headers |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment