Skip to content

Instantly share code, notes, and snippets.

@dmauser
Last active October 28, 2025 23:40
Show Gist options
  • Select an option

  • Save dmauser/e75138a5038785dc9a6ed039902f2f5a to your computer and use it in GitHub Desktop.

Select an option

Save dmauser/e75138a5038785dc9a6ed039902f2f5a to your computer and use it in GitHub Desktop.
archive-stg-sample
# --- Inputs ---
$ResourceGroup = "<rg-name>"
$StorageAccount = "<storage-account-name>"
$Container = "<container-name>"
$BlobName = "<blob-name>"
# Optional: use MSI/Azure login (instead of key)
Connect-AzAccount | Out-Null
# Get storage context
$acct = Get-AzStorageAccount -ResourceGroupName $ResourceGroup -Name $StorageAccount
$ctx = $acct.Context
# 1) Issue rehydrate request: Archive -> Cold
# Valid values: Hot | Cool | Cold | Archive
# Rehydrate priority: Standard | High
Set-AzStorageBlobTier `
-Context $ctx `
-Container $Container `
-Blob $BlobName `
-Tier Cold `
-RehydratePriority High
Write-Host "Rehydrate requested: Archive → Cold (Priority=High)."
# 2) Poll status until it is online (rehydration is async)
function Get-RehydrateState {
param($Ctx, $Container, $Blob)
$props = Get-AzStorageBlob -Context $Ctx -Container $Container -Blob $Blob
# ArchiveStatus is non-empty while rehydration is pending (e.g., 'rehydrate-pending')
[PSCustomObject]@{
AccessTier = $props.ICloudBlob.Properties.StandardBlobTier
ArchiveStatus = $props.ICloudBlob.Properties.ArchiveStatus
BlobETag = $props.ICloudBlob.Properties.ETag
LastModified = $props.ICloudBlob.Properties.LastModified.UtcDateTime
}
}
Write-Host "Polling rehydrate status (Ctrl+C to stop)..."
do {
$state = Get-RehydrateState -Ctx $ctx -Container $Container -Blob $BlobName
$ts = (Get-Date).ToString("s")
Write-Host "[$ts] Tier=$($state.AccessTier) ArchiveStatus=$($state.ArchiveStatus)"
Start-Sleep -Seconds 30
} while ($state.ArchiveStatus) # when ArchiveStatus is empty, the blob is online at the target tier
Write-Host "Rehydration complete. Blob is now online in the Cold tier."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment