I am using PowerShell to interact with Azure Table Storage, but I keep receiving a 403 Forbidden error.
Here is the relevant part of my script:
function InsertReplaceTableEntity($TableName, $PartitionKey, $Rowkey, $entity) {
$version = "2017-04-17"
$resource = "$tableName(PartitionKey='$PartitionKey',RowKey='$Rowkey')"
$table_url = "https://$storageAccount.table.core.windows.net/$resource"
Write-Host "Table URL: $table_url"
$GMTTime = (Get-Date).ToUniversalTime().toString('R')
$stringToSign = "$GMTTime`n/$storageAccount/$resource"
Write-Host "String to Sign: $stringToSign"
$hmacsha = New-Object System.Security.Cryptography.HMACSHA256
$hmacsha.key = [Convert]::FromBase64String($ADL_KEY)
$signature = $hmacsha.ComputeHash([Text.Encoding]::UTF8.GetBytes($stringToSign))
$signature = [Convert]::ToBase64String($signature)
Write-Host "Signature: $signature"
$headers = @{
'x-ms-date' = $GMTTime
Authorization = "SharedKeyLite " + $storageAccount + ":" + $signature
"x-ms-version" = $version
Accept = "application/json;odata=fullmetadata"
}
Write-Host "Headers: $($headers | ConvertTo-Json)"
$body = $entity | ConvertTo-Json
Write-Host "$body"
$item = Invoke-RestMethod -Method PUT -Uri $table_url -Headers $headers -Body $body -ContentType application/json
}