Azure:使用Powershell从Azure存储中删除所有*test.zip Blob
我想删除azure存储容器中文件名包含test.zip的所有文件 我能够获取所有文件并将其导出到如下文件:Azure:使用Powershell从Azure存储中删除所有*test.zip Blob,powershell,azure,azure-storage,Powershell,Azure,Azure Storage,我想删除azure存储容器中文件名包含test.zip的所有文件 我能够获取所有文件并将其导出到如下文件: $context = New-AzureStorageContext -StorageAccountName ACCOUNTNAME ` -StorageAccountKey ACCOUNTKEY get-azurestorageblob -Container CONTAINERNAME
$context = New-AzureStorageContext -StorageAccountName ACCOUNTNAME `
-StorageAccountKey ACCOUNTKEY
get-azurestorageblob -Container CONTAINERNAME `
-blob *test.zip `
-Context $context | Out-File c:\files\f.txt `
-width 500
使用
remove-azurestorageblob
命令删除所有结果的最简单方法是什么?由于blob存储此时只支持单个blob删除(即不支持批量删除),因此您唯一的选择是从输出文件中读取单个blob并逐个删除blob
根据以下评论,请尝试以下操作:
$context = New-AzureStorageContext -StorageAccountName "account name" -StorageAccountKey "account key"
Get-AzureStorageBlob -Container "containername" -blob *test.zip -Context $context | Remove-AzureStorageBlob
# Define Variables
$RESOURCE_GROUP_NAME = my-resource-group
$STORAGE_ACCOUNT_NAME = myapplication
# Get Storage Account Context
$STORAGE_ACCOUNT = Get-AzStorageAccount -ResourceGroupName $RESOURCE_GROUP_NAME -AccountName $STORAGE_ACCOUNT_NAME
$CONTEXT = $STORAGE_ACCOUNT.Context
# Remove all test.zip Files from the $web Storage Container
Get-AzStorageBlob -Container '$web' -Blob *test.zip -Context $CONTEXT | Remove-AzStorageBlob
上面的脚本将首先列出匹配的blob,然后逐个删除它们。我在Octopus Deploy中使用Powershell为静态网站托管设置Azure存储帐户时遇到了这个难题 以下是我如何修复它的方法: 我使用了以下命令:
$context = New-AzureStorageContext -StorageAccountName "account name" -StorageAccountKey "account key"
Get-AzureStorageBlob -Container "containername" -blob *test.zip -Context $context | Remove-AzureStorageBlob
# Define Variables
$RESOURCE_GROUP_NAME = my-resource-group
$STORAGE_ACCOUNT_NAME = myapplication
# Get Storage Account Context
$STORAGE_ACCOUNT = Get-AzStorageAccount -ResourceGroupName $RESOURCE_GROUP_NAME -AccountName $STORAGE_ACCOUNT_NAME
$CONTEXT = $STORAGE_ACCOUNT.Context
# Remove all test.zip Files from the $web Storage Container
Get-AzStorageBlob -Container '$web' -Blob *test.zip -Context $CONTEXT | Remove-AzStorageBlob
或
就这些
我希望这有帮助谢谢瓜拉夫!您的powershell技能是否有可能扩展到能够帮助我编写一个脚本,以便使用foreach循环读取和删除?这正是我想要弄明白的:)。一旦找到解决方案,将更新我的答案(考虑到我在PowerShell方面缺乏专业知识,这可能并不理想)。是否需要将其保存到文件中?如果您通过
获取azurestorageblob
获取列表后删除Blob是否可以?可以删除而不保存列表。更新了我的答案。请查收。这是最简单和干净的方法