【发布时间】:2021-05-23 17:09:32
【问题描述】:
我想查看特定存储帐户中存储容器的存储 blob 所以我运行了以下命令:
$storageAccountName = "teststor"
$resourceGroup = "RgDev"
$StorageAccountKey = (Get-AzStorageAccountKey -ResourceGroupName $resourceGroup -Name $storageAccountName).Value[0]
$context=New-AzStorageContext -StorageAccountName $storageAccountName -StorageAccountKey $storageAccountkey
Get-AzStorageContainer -Context $context
$ContainerName = Get-AzStorageContainer -Context $context
现在当我运行最终命令时:
Get-AzStorageBlob -Container $ContainerName -Context $context
我收到以下错误:
PS C:\WINDOWS\system32> Get-AzStorageBlob -Container $ContainerName -Context $ctx
Get-AzStorageBlob : Cannot convert 'System.Object[]' to the type 'System.String' required by parameter
'Container'. Specified method is not supported.
At line:1 char:31
+ Get-AzStorageBlob -Container $ContainerName -Context $ctx
+ ~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Get-AzStorageBlob], ParameterBindingException
+ FullyQualifiedErrorId : CannotConvertArgument,Microsoft.WindowsAzure.Commands.Storage.Blob.Cmdlet.GetAzur
eStorageBlobCommand
知道如何解决这个问题
我现在收到此错误
PS C:\WINDOWS\system32> $AzContainer = Get-AzStorageContainer -Context $context
PS C:\WINDOWS\system32> $AzContainer
Blob End Point: https://testhalifax.blob.core.windows.net/
Name PublicAccess LastModified
---- ------------ ------------
koltest1 Off 9/20/2020 2:22:04 AM +00:00
teststorhal Off 9/1/2020 8:25:44 PM +00:00
PS C:\WINDOWS\system32> $BlobContainer = $AzContainer.CloudBlobContainer
PS C:\WINDOWS\system32> $BlobContainer
Blob End Point: https://testhalifax.blob.core.windows.net/
Name Uri LastModified
---- --- ------------
koltest1 https://testhalifax.blob.core.windows.net/koltest1 2020-09-20 02:22:04Z
teststorhal https://testhalifax.blob.core.windows.net/teststorhal 2020-09-01 20:25:44Z
PS C:\WINDOWS\system32> $ContainerName = $BlobContainer.Name
PS C:\WINDOWS\system32> $ContainerName
koltest1
teststorhal
PS C:\WINDOWS\system32> Get-AzStorageBlob -Container $ContainerName -Context $context
Get-AzStorageBlob : Cannot convert 'System.Object[]' to the type 'System.String' required by parameter
'Container'. Specified method is not supported.
At line:1 char:31
+ Get-AzStorageBlob -Container $ContainerName -Context $context
+ ~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Get-AzStorageBlob], ParameterBindingException
+ FullyQualifiedErrorId : CannotConvertArgument,Microsoft.WindowsAzure.Commands.Storage.Blob.Cmdlet.GetAzur
eStorageBlobCommand
【问题讨论】:
-
报告的错误与您粘贴的命令不同。错误显示
$ContainerName.Name,而您的代码 sn-p 显示$ContainerName。根据docs.microsoft.com/en-us/powershell/module/az.storage/…Get-AzStorageContainer应该只输出一个字符串。 -
抱歉之前的截图有误,我现在放正确的错误
-
可能这是返回多个容器
$ContainerName = Get-AzStorageContainer -Context $context -
是的,@TheGameiswar 你是对的,当我运行 $ContainerName 时我有多个容器
标签: azure powershell azure-blob-storage