Updated
Script that i got from https://github.com/directorcia/Azure/blob/master/az-blob-tierset.ps1
Run in Powershell
#Module Installation
Install-Module -Name Az -AllowClobber
#Connection to Azure, need to login via browser
connect-azaccount
$systemmessagecolor = “cyan”
$processmessagecolor = “green”
$storageaccountname = “storage account name”
$storageresourcegroup = “storage resource group”
$storagetier = “Archive” # Hot, Cool or Archive
clear-host
write-host -foregroundcolor $systemmessagecolor “Script started`n”
write-host -foregroundcolor $processmessagecolor “Get Storage Account”
$storageaccount = Get-AzStorageAccount -name $storageaccountname -ResourceGroupName $storageresourcegroup
write-host -foregroundcolor $processmessagecolor “Get Storage Account key”
$key = (get-azstorageaccountkey -ResourceGroupName $storageaccount.ResourceGroupName -Name $storageaccount.StorageAccountName).value[0]
write-host -foregroundcolor $processmessagecolor “Get Storage context”
$context = New-AzstorageContext -StorageAccountName $storageaccount.StorageAccountName -StorageAccountKey $key
write-host -foregroundcolor $processmessagecolor “Get Storage containers”
$storagecontainers = get-azstoragecontainer -Context $context
write-host -foregroundcolor $processmessagecolor “Get Items”
$Blobs = @()
foreach ($StorageContainer in $StorageContainers) {
$Blobs += Get-AzStorageBlob -Context $Context -Container $StorageContainer.Name
}
write-host -foregroundcolor $processmessagecolor “Change tier of all items`n”
Foreach ($Blob in $Blobs) {
#Set tier of all blobs to desired tier
$blob.icloudblob.SetStandardBlobTier($StorageTier)
write-host “Changed -“, $blob.name
}
write-host -foregroundcolor $systemmessagecolor “Script finished`n”
—————————- old version—————————-
Module Installation
Install-Module -Name AzureRM
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned
Import-Module AzureRM
SCRIPT
#Define storage account information
$StorageAccount = "xxxxx"
$StorageAccountKey = "xxxxx"
$containername = "xxxxx"
#Create a storage context
$context = New-AzStorageContext -StorageAccountName $StorageAccount -StorageAccountKey $StorageAccountKey
# Get the blobs
$blobs = Get-AzStorageBlob -Container $containername -Context $context
$blob = $blobs[0]
$blob.ICloudBlob.SetStandardBlobTier("Archive")
$StgAcc = “azuredata”
$StgKey = “qPogbxIVfFD1s57bFemCoQT6xMRyLNCGc0yho+ldeX0aNdYNmMgl9kTQ==”
$Container = “photo”
$ctx = New-AzureStorageContext -StorageAccountName $StgAcc -StorageAccountKey $StgKey
Connect-AzureRmAccount
Get all the blobs in container
$blob = Get-AzureStorageBlob -Container $Container -Context $ctx
Set tier of all the blobs to Archive
$blob.icloudblob.setstandardblobtier(“Archive”)
With reference to https://webmakers.co.nz/how-to-convert-entire-data-in-a-blob-storage-from-cool-storage-tier-into-archive-access-tier/
