使用Powershell获取Azure容器Blob内容

时间:2020-03-13 10:44:30

标签: powershell blob azure-storage-blobs azure-blob-storage

我正在尝试使用Powershell获得天蓝色的容器blob内容。

代码

$Ctx = New-AzStorageContext -StorageAccountName abc -StorageAccountKey 'xxxx=='
$latestBuild = Get-AzStorageBlob -Context $Ctx -Container jmeter -blob "Script\Load1"
if($latestBuild -ne $null)
{
    foreach($item in $latestBuild)
    { 
        Get-AzStorageBlobContent -Blob $item.name -Container jmeter -Destination C:\ -Context $Ctx -Force
    }
}
else
{
    write-host "Blob is empty !!!"
}

错误

Get-AzStorageBlob : Can not find blob 'Script\Load1' in container 'jmeter', or the blob type is unsupported.
At line:2 char:16
+ ... testBuild = Get-AzStorageBlob -Context $Ctx -Container jmeter -blob " ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (:) [Get-AzStorageBlob], ResourceNotFoundException
    + FullyQualifiedErrorId : ResourceNotFoundException,Microsoft.WindowsAzure.Commands.Storage.Blob.Cmdlet.GetAzureStorageBlobCommand

Blob is empty !!!

Load1文件夹中存在两个文件:

enter image description here

1 个答案:

答案 0 :(得分:1)

这不是它的工作方式,您必须做不同的事情:

Get-AzStorageBlob -Context $Ctx -Container jmeter -Prefix "Script/Load1"

或者只是:

Get-AzStorageBlob -Context $Ctx -Container jmeter -Blob "Script/Load1*"

https://docs.microsoft.com/en-us/powershell/module/az.storage/get-azstorageblob?view=azps-3.6.1