【问题标题】:How to create azure storage table using rest api via powershell如何通过powershell使用rest api创建天蓝色存储表
【发布时间】:2017-01-19 14:56:49
【问题描述】:

我知道如何使用 PowerShell 和门户创建 azure 存储表,有人可以指导如何使用 rest api 来创建它

$jsonbody = @{}
$authorization = ""
Invoke-restmethod -uri "" 

【问题讨论】:

  • 这个问题你解决了吗,有更新吗?

标签: powershell azure-table-storage


【解决方案1】:

作为一种简单的方法,您可以利用New-AzureStorageTable cmdlet 创建您的存储表,如下所示:

#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

如需了解更多详情,请关注tutorial官方,了解如何在 Azure Storage 中创建表。

此外,您可以利用Invoke-restmethod 调用Create Table REST API 在您的存储帐户中创建一个表。您可以按照以下命令:

#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

结果:

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-11-20
    • 2012-11-17
    • 2018-05-12
    • 1970-01-01
    • 1970-01-01
    • 2018-01-15
    • 1970-01-01
    • 2016-11-27
    相关资源
    最近更新 更多