Skip to content

Instantly share code, notes, and snippets.

@darrenjrobinson
Last active December 4, 2020 14:52
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save darrenjrobinson/df83178fb7247fa3e5891c4286027625 to your computer and use it in GitHub Desktop.
Save darrenjrobinson/df83178fb7247fa3e5891c4286027625 to your computer and use it in GitHub Desktop.
Query Azure Table Storage using PowerShell. Associated Blog Post https://blog.darrenjrobinson.com/loading-and-querying-data-in-azure-table-storage-using-powershell/
$storageAccountName = "myStorageAccount"
$storageAccountkey = "abcdefghi123456789YUoxr5mqAmTRgeXSh6Vvx6q+O6aiV9pMaCYbrUo1x/Abcdeb=="
$tableName = "NICVendors"
$apiVersion = "2017-04-17"
$tableURL = "https://$($storageAccountName).table.core.windows.net/$($tableName)"
$GMTime = (Get-Date).ToUniversalTime().toString('R')
$string = "$($GMTime)`n/$($storageAccountName)/$($tableName)"
$hmacsha = New-Object System.Security.Cryptography.HMACSHA256
$hmacsha.key = [Convert]::FromBase64String($storageAccountkey)
$signature = $hmacsha.ComputeHash([Text.Encoding]::UTF8.GetBytes($string))
$signature = [Convert]::ToBase64String($signature)
$headers = @{
Authorization = "SharedKeyLite " + $storageAccountName + ":" + $signature
Accept = "application/json;odata=fullmetadata"
'x-ms-date' = $GMTime
"x-ms-version" = $apiVersion
}
$queryURL = "$($tableURL)?`$filter=(Vendor eq 'Dell Inc.')"
$NICitem = Invoke-RestMethod -Method GET -Uri $queryURL -Headers $headers -ContentType application/json
$NICitem.value
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment