0

I have an idea how to create azure storage tables using PowerShell and portal, can some one guide how to create it using rest api like

$jsonbody = @{}
$authorization = ""
Invoke-restmethod -uri "" 
1
  • Have you solved this issue, any updates? Commented Jan 23, 2017 at 1:18

1 Answer 1

3

For a simple way, you could leverage New-AzureStorageTable cmdlet to create your storage table as follows:

#Define the storage account and context.
$StorageAccountName = "yourstorageaccountname"
$StorageAccountKey = "yourstorageaccountkey"
$Ctx = New-AzureStorageContext $StorageAccountName -StorageAccountKey $StorageAccountKey

#Create a new table.
$tabName = "yourtablename"
New-AzureStorageTable –Name $tabName –Context $Ctx

For more details, you could follow this official tutorial about how to create a table in Azure Storage.

Also, you could leverage Invoke-restmethod to invoke Create Table REST API to create a table in your storage account. You could follow the following command:

#Define the storage account.
$StorageAccount = "yourstorageaccountname"
$Key = "yourstorageaccountkey"

$sharedKey = [System.Convert]::FromBase64String($Key)
$date = [System.DateTime]::UtcNow.ToString("R")

$tabName= "yourtablename"
$contentType="application/json"
$accept="application/json;odata=minimalmetadata"
$canonicalizedResource = "/Tables"
$x_ms_version="2015-04-05"
$stringToSign = "POST`n`n$contentType`n$date`n/$StorageAccount$canonicalizedResource"
$hasher = New-Object System.Security.Cryptography.HMACSHA256
$hasher.Key = $sharedKey

$signedSignature = [System.Convert]::ToBase64String($hasher.ComputeHash([System.Text.Encoding]::UTF8.GetBytes($stringToSign)))

$authHeader = "SharedKey ${StorageAccount}:$signedSignature"

$headers = @{"x-ms-date"=$date
            "Authorization"=$authHeader
            "Accept"=$accept
            "Content-Type"=$contentType
            "x-ms-version"=$x_ms_version}

$hash=@{"TableName"=$tabName}
$json=$hash | convertto-json

Invoke-RestMethod -Method "POST" -Uri "https://$StorageAccount.table.core.windows.net/Tables" -Headers $headers -Body $json

Result:

enter image description here

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.