将 StorageAccount 密钥传递给新上下文时出错

Error while passing StorageAccount Key to new Context

以下代码在昨天之前工作正常,但今天它给我一个错误,如下所述。

$StorageAccountName = "xyz"
$StorageAccountKey = Get-AzureRmStorageAccountKey -StorageAccountName $StorageAccountName
$Ctx = New-AzureStorageContext $StorageAccountName -StorageAccountKey $StorageAccountKey.Primary

尝试用

替换上面代码中的最后一行
$Ctx = New-AzureStorageContext $StorageAccountName -StorageAccountKey $StorageAccountKey.key1

这是错误:

New-AzureStorageContext : Cannot validate argument on parameter 'StorageAccountKey'. The argument is null or empty.
Provide an argument that is not null or empty, and then try the command again.
$Ctx = New-AzureStorageContext $StorageAccountName -StorageAccountKey
 $StorageAccountKey.value[0]

您可以使用 $StorageAccount | Get-Member

轻松解决这个问题