我正在嘗試從 PowerShell 獲取 Azure Blob 容器中存在的 Blob 串列。
我已經嘗試在我的腳本中使用函式來做到這一點。但它什么也沒回傳。
我的腳本有點像這樣(隱藏資源名稱):
## Connect to Azure Account
Connect-AzAccount
Function GetBlobs
{
## Get the storage account
$storageAcc=Get-AzStorageAccount -ResourceGroupName $resourceGroupName -Name $storageAccountName
## Get all the containers
$containers=Get-AzStorageContainer
## Get all the blobs
$blobs=Get-AzStorageBlob -Container $containerName
## Loop through all the blobs
foreach($blob in $blobs)
{
write-host $blob.Name
}
}
GetBlobs
但是盡管我的容器中有斑點,但它回傳空白。我不知道我做錯了什么。
有人可以幫我嗎?我也是這個平臺的新手,不知道我是否以正確的方式提出問題。
uj5u.com熱心網友回復:
我已經在我的環境中測驗過了。它成功回傳了 blob 串列。

嘗試包括storage account context. 如果您想了解更多相關資訊,請通過此鏈接。包含這些之后,您可能會成功獲取 blob 串列。
請檢查您的腳本是否是這樣的:
$resourceGroupName = "your_RG"
$storageAccountName= "your_SA"
$containerName= "your_container_name"
## Connect to Azure Account
Connect-AzAccount
## Function to get all the blobs
Function GetBlobs
{
$storageAcc=Get-AzStorageAccount -ResourceGroupName $resourceGroupName -Name $storageAccountName
## Get the storage account context
$context=$storageAcc.Context
## Get all the containers
$containers=Get-AzStorageContainer -Context $context
$blobs=Get-AzStorageBlob -Container $containerName -Context $context
foreach ($blob in $blobs)
{
write-host $blob.Name
}
}
GetBlobs
如果有幫助,請檢查以下參考。
參考:
如何使用 PowerShell (c-sharpcorner.com) 從 Azure 存盤帳戶獲取所有 Blob
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/444140.html
