Ескертпе
Бұл бетке кіру үшін қатынас шегін айқындау қажет. Жүйеге кіруді немесе каталогтарды өзгертуді байқап көруге болады.
Бұл бетке кіру үшін қатынас шегін айқындау қажет. Каталогтарды өзгертуді байқап көруге болады.
Скрипт удаляет контейнеры в хранилище объектов Azure на основе префикса в имени контейнера.
Для этого примера требуется Azure PowerShell. Чтобы узнать версию, выполните команду Get-Module -ListAvailable Az.
Если вам необходимо выполнить установку или обновление, см. статью об установке модуля Azure PowerShell.
Запустите командлет Connect AzAccount, чтобы подключиться к Azure.
Если у вас нет аккаунта Azure, создайте бесплатную учетную запись перед началом.
Пример скрипта
# this script will show how to delete containers with a specific prefix
# the prefix this will search for is "image".
# before running this, you need to create a storage account, create some containers,
# some having the same prefix so you can test this
# note: this retrieves all of the matching containers in one command
# if you are going to run this against a storage account with a lot of containers
# (more than a couple hundred), use continuation tokens to retrieve
# the list of containers. We will be adding a sample showing that scenario in the future.
# these are for the storage account to be used
# and the prefix for which to search
$resourceGroup = "containerdeletetestrg"
$storageAccountName = "containerdeletetest"
$prefix = "image"
# get a reference to the storage account and the context
$storageAccount = Get-AzStorageAccount `
-ResourceGroupName $resourceGroup `
-Name $storageAccountName
$ctx = $storageAccount.Context
# list all containers in the storage account
Write-Host "All containers"
Get-AzStorageContainer -Context $ctx | select Name
# retrieve list of containers to delete
$listOfContainersToDelete = Get-AzStorageContainer -Context $ctx -Prefix $prefix
# write list of containers to be deleted
Write-Host "Containers to be deleted"
$listOfContainersToDelete | select Name
# delete the containers; this pipes the result of the listing of the containers to delete
# into the Remove-AzStorageContainer command. It handles all of the containers in the list.
Write-Host "Deleting containers"
$listOfContainersToDelete | Remove-AzStorageContainer -Context $ctx
# show list of containers not deleted
Write-Host "All containers not deleted"
Get-AzStorageContainer -Context $ctx | select Name
Очистка и упорядочивание процесса развертывания
Выполните команду ниже, чтобы удалить группу ресурсов, оставшиеся контейнеры и все связанные ресурсы.
Remove-AzResourceGroup -Name containerdeletetestrg
Описание скрипта
Этот скрипт использует следующие команды для удаления контейнеров на основе префикса имени контейнера. Для каждого элемента в таблице приведены ссылки на документацию по команде.
| Команда | Примечания. |
|---|---|
| Get-AzStorageAccount | Возвращает определенную учетную запись хранения или все учетные записи хранения в группе ресурсов или подписке. |
| Get-AzStorageContainer | Перечисляет контейнеры хранения, связанные с учетной записью хранения. |
| Remove-AzStorageContainer | Удаляет указанный контейнер хранилища. |
Следующие шаги
Дополнительные сведения о модуле Azure PowerShell см. в документации по Azure PowerShell.
Дополнительные примеры скриптов PowerShell для хранилища можно найти в разделе Примеры скриптов Azure PowerShell для хранилища BLOB-объектов Azure.