azure - 尝试创建 Blob 容器时,无法将 'System.Object[]' 转换为参数 'System.String' 所需的类型 'StorageAccountKey'

标签 azure powershell

我尝试使用以下语句在存储帐户内创建一个容器:

New-AzResourceGroup -Name $rg_bk -Location $Region -Tag @{CompanyName = $Customer_Name }
$StorageAccountName = "bacpacssa$(Get-Random)"
New-AzStorageAccount -ResourceGroupName $rg_bk -Name $StorageAccountName -Location $Region -SkuName Standard_GRS -Tag @{CompanyName = $Customer_Name } -Kind BlobStorage -AccessTier Cool
$storageKey = (Get-AzStorageAccountKey -ResourceGroupName $rg_bk -Name $StorageAccountName).Value 
$StorageContext = New-AzStorageContext -StorageAccountName $StorageAccountName -StorageAccountKey $storageKey 
$ContainerName = "databasesbacpac$(Get-Random)"
New-AzStorageContainer -Name $ContainerName -Context $StorageContext -Permission Off

但我也收到以下错误

New-AzStorageContext : Cannot convert 'System.Object[]' to the type 'System.String' required by parameter 'StorageAccountKey'. Specified method is not supported.

最佳答案

这一行:

$storageKey = (Get-AzStorageAccountKey -ResourceGroupName $rg_bk -Name $StorageAccountName).Value 

返回两个对象,因此您可以在数组中获取每个对象的值。您的下一个 cmdlet ( New-AzStorageContext ) 需要一个 -StorageAccountKey 值。

如果你只想使用第一个,你可以像这样修复它。

$storageKey = (Get-AzStorageAccountKey -ResourceGroupName $rg_bk -Name $StorageAccountName)[0].Value 

这意味着您只能使用 key1 中的值。如果你想使用key2,可以将其更改为[1]

关于azure - 尝试创建 Blob 容器时,无法将 'System.Object[]' 转换为参数 'System.String' 所需的类型 'StorageAccountKey',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64212072/

相关文章:

Azure服务总线: How to correctly check if Subscription already exists?

xml - 每次部署后使用 powershell 自动增加 application.config 的版本

c# - 如何不序列化默认值

Azure - 在 Java Spring Boot 中使用用户管理身份访问 Key Vault : Error Details: ManagedIdentityCredential authentication unavailable?

c# - 如何从 Azure 角色内部检测当前订阅 ID?

powershell - ConvertTo-Json 格式化

azure - 为特定 blob 创建 SAS token ,而不是同一存储帐户中的其他 blob

Powershell 编辑 mp3 信息

powershell - 如何使用命令提示符或Powershell关闭投影机?

azure - DBFS AZURE Databricks - 文件存储和 DBFS 的差异