2016-12-05 41 views
0

以下代碼直到昨天才正常工作,但今天它正在給我一個如下所述的錯誤。將StorageAccount密鑰傳遞到新的上下文時出錯

$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. 

回答

1
$Ctx = New-AzureStorageContext $StorageAccountName -StorageAccountKey 
$StorageAccountKey.value[0] 

您可以輕鬆地自己找出答案與$StorageAccount | Get-Member

+0

這已經工作,但缺乏riosity想知道使用'$ StorageAccountKey.Primary'或'$ StorageAccountKey.key1' –

+1

這個問題,我已經給你解釋了。 '$ StorageAccountKey'對象不再具有這些屬性,您可以檢查自己,執行'| gm'然後看。 – 4c74356b41