|
| 1 | + |
| 2 | +# Note: If we have immuatble policy with Timebased retention the blobs has to be in conatiner til lthe retentione xexpires and then only we can delete the blobs |
| 3 | +#This script helps to List all the blobs with version along with Immutable retention expiry days |
| 4 | + |
| 5 | +#Disclaimer |
| 6 | +#By using the following materials or sample code you agree to be bound by the license terms below |
| 7 | +#and the Microsoft Partner Program Agreement the terms of which are incorporated herein by this reference. |
| 8 | +#These license terms are an agreement between Microsoft Corporation (or, if applicable based on where you |
| 9 | +#are located, one of its affiliates) and you. Any materials (other than sample code) we provide to you |
| 10 | +#are for your internal use only. Any sample code is provided for the purpose of illustration only and is |
| 11 | +#not intended to be used in a production environment. We grant you a nonexclusive, royalty-free right to |
| 12 | +#use and modify the sample code and to reproduce and distribute the object code form of the sample code, |
| 13 | +#provided that you agree: (i) to not use Microsoft’s name, logo, or trademarks to market your software product |
| 14 | +#in which the sample code is embedded; (ii) to include a valid copyright notice on your software product in |
| 15 | +#which the sample code is embedded; (iii) to provide on behalf of and for the benefit of your subcontractors |
| 16 | +#a disclaimer of warranties, exclusion of liability for indirect and consequential damages and a reasonable |
| 17 | +#limitation of liability; and (iv) to indemnify, hold harmless, and defend Microsoft, its affiliates and |
| 18 | +#suppliers from and against any third party claims or lawsuits, including attorneys’ fees, that arise or result |
| 19 | +#from the use or distribution of the sample code." |
| 20 | + |
| 21 | +# Connect using Azure AD (interactive login) |
| 22 | +Connect-AzAccount |
| 23 | + |
| 24 | +# Set the subscription context |
| 25 | +Set-AzContext -Subscription "subID" |
| 26 | + |
| 27 | +# Define parameters |
| 28 | +$resourceGroup = "RG name" |
| 29 | +$storageAccountName = "SA name" |
| 30 | +$containerName = "Container name " |
| 31 | + |
| 32 | +# Get storage account and context |
| 33 | +$storageAccount = Get-AzStorageAccount -ResourceGroupName $resourceGroup -Name $storageAccountName |
| 34 | +$context = $storageAccount.Context |
| 35 | + |
| 36 | +# Get blob versions |
| 37 | +$blobVersions = Get-AzStorageBlob -Container $containerName -Context $context -IncludeVersion |
| 38 | + |
| 39 | +# Loop through each blob version and display retention info |
| 40 | +foreach ($blob in $blobVersions) { |
| 41 | + $properties = $blob.BlobClient.GetProperties() |
| 42 | + $immutability = $properties.Value.ImmutabilityPolicy |
| 43 | + |
| 44 | + Write-Host "Blob Name: $($blob.Name)" |
| 45 | + Write-Host "Retention Expiry: $($immutability.ExpiresOn)" |
| 46 | + Write-Host "-----------------------------" |
| 47 | +} |
| 48 | + |
0 commit comments