Menghitung ukuran kontainer blob dengan PowerShell
Skrip ini menghitung ukuran kontainer di Azure Blob Storage. Skrip ini pertama-tama akan menampilkan jumlah total byte yang digunakan oleh blob di dalam kontainer, kemudian menampilkan nama individu dan nama panjangnya masing-masing.
Sampel ini memerlukan Azure PowerShell. Jalankan Get-Module -ListAvailable Az untuk menemukan versinya.
Jika Anda perlu menginstal atau meningkatkan, lihat Menginstal modul Azure PowerShell.
Jalankan cmdlet Connect-AzAccount untuk tersambung ke Azure.
Jika Anda tidak memiliki langganan Azure, buat akun gratis Azure sebelum memulai.
Penting
Skrip PowerShell ini memberikan perkiraan ukuran untuk kontainer dan tidak boleh digunakan untuk perhitungan penagihan. Untuk skrip yang menghitung ukuran kontainer untuk keperluan penagihan, lihat Menghitung ukuran kontainer penyimpanan Blob untuk keperluan penagihan.
Sampel skrip
# this script will show how to get the total size of the blobs in a container
# before running this, you need to create a storage account, create a container,
# and upload some blobs into the container
# note: this retrieves all of the blobs in the container in one command.
# if you are going to run this against a container with a lot of blobs
# (more than a couple hundred), use continuation tokens to retrieve
# the list of blobs.
# these are for the storage account to be used
$resourceGroup = "bloblisttestrg"
$storageAccountName = "contosobloblisttest"
$containerName = "listtestblobs"
# get a reference to the storage account and the context
$storageAccount = Get-AzStorageAccount `
-ResourceGroupName $resourceGroup `
-Name $storageAccountName
$ctx = $storageAccount.Context
# get a list of all of the blobs in the container
$listOfBlobs = Get-AzStorageBlob -Container $ContainerName -Context $ctx
# zero out our total
$length = 0
# this loops through the list of blobs and retrieves the length for each blob
# and adds it to the total
$listOfBlobs | ForEach-Object {$length = $length + $_.Length}
# output the blobs and their sizes and the total
Write-Host "List of Blobs and their size (length)"
Write-Host " "
$listOfBlobs | select Name, Length
Write-Host " "
Write-Host "Total Length = " $length
Membersihkan penyebaran
Jalankan perintah berikut untuk menghapus grup sumber daya, kontainer, dan semua sumber daya terkait.
Remove-AzResourceGroup -Name bloblisttestrg
Penjelasan skrip
Skrip ini menggunakan perintah berikut untuk menghitung ukuran kontainer penyimpanan Blob. Setiap item dalam tabel ditautkan ke dokumentasi spesifik perintah.
| Perintah | Catatan |
|---|---|
| Dapatkan-AkunPenyimpananAz | Mendapatkan akun Penyimpanan tertentu atau semua akun Penyimpanan dalam grup sumber daya atau langganan. |
| Dapatkan-BlobPenyimpananAz | Mencantumkan blob dalam kontainer. |
Langkah berikutnya
Untuk skrip yang menghitung ukuran kontainer untuk keperluan penagihan, lihat Menghitung ukuran kontainer penyimpanan Blob untuk keperluan penagihan.
Untuk informasi selengkapnya tentang modul Azure PowerShell, lihat dokumentasi Azure PowerShell.
Temukan lebih banyak sampel skrip PowerShell di sampel PowerShell untuk Azure Storage.