March 3, 2018

Azure - Change Blob Tier script

Simple PowerShell script to set Archive Access Tier for all Blobs older than 1 month in a specific storage account.

Login-AzureRmAccount
$StorageAccount = "Your SA Name"
$StorageAccountKey = "SA Key"
$ContainerName ="Container Name"
$Context = New-AzureStorageContext -StorageAccountName $StorageAccount -StorageAccountKey $StorageAccountKey
$Blobs = Get-AzureStorageBlob -Container $ContainerName -Context $Context
Foreach ($Blob in $Blobs | where {$_.LastModified -lt (Get-Date).AddMonths(-1)})
{$Blob.ICloudBlob.SetStandardBlobTier("Archive")}

Or run $Blobs.ICloudBlob.SetStandardBlobTier("Archive")” instead Foreach” loop to set all blobs.

2 comments:

  1. This works in Azure Automation, just need to update your modules:

    https://docs.microsoft.com/en-us/azure/automation/automation-update-azure-modules

    ReplyDelete