مشاركة عبر


حذف الحاويات بناءً على بادئة اسم الحاوية

يحذف هذا البرنامج النصي الحاويات في تخزين Azure Blob استناداً إلى بادئة في اسم الحاوية.

يتطلب هذا النموذج Azure PowerShell. قم بتشغيل Get-Module -ListAvailable Az للعثور على الإصدار. إذا كنت بحاجة إلى التثبيت أو الترقية، راجع تثبيت وحدة Azure PowerShell.

تشغيل cmdlet Connect-AzAccount للاتصال بـ Azure.

إذا لم يكن لديك اشتراك في 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 Blob.