如何通过PowerShell使用Rest API创建Azure存储表 [英] How to create azure storage table using rest api via powershell
本文介绍了如何通过PowerShell使用Rest API创建Azure存储表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个想法,如何使用PowerShell和门户网站创建Azure存储表,可以有人指导如何使用REST API(如
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 ""
推荐答案
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
有关更多详细信息,您可以关注此官方关于如何在Azure存储中创建表的教程.
For more details, you could follow this official tutorial about how to create a table in Azure Storage.
此外,您可以利用Invoke-restmethod
调用创建表 REST API即可在您的存储帐户中创建表.您可以遵循以下命令:
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
结果:
这篇关于如何通过PowerShell使用Rest API创建Azure存储表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文