Skip to content

Instantly share code, notes, and snippets.

@MauricioZa
Created February 15, 2023 14:49
Show Gist options
  • Select an option

  • Save MauricioZa/b5d8c1645a82daef2d33eaaf9fc90136 to your computer and use it in GitHub Desktop.

Select an option

Save MauricioZa/b5d8c1645a82daef2d33eaaf9fc90136 to your computer and use it in GitHub Desktop.
# Set Azure Storage context
$storageContext = New-AzStorageContext -StorageAccountName 'mystorageaccount' -StorageAccountKey "pleasInsertHereTheStorageAccountKey"
# Set source and destination containers
$containerName = 'container'
$newContainerName = 'newcontainer'
# Get all blobs in source container
$blobNames = Get-AzStorageBlob -Container $containername -Context $storageContext
# Iterate through all blobs
foreach ($blobName in $blobNames) {
# Insert the function to get the new name of the blob
# The line below generates a random name. Substitute it with your own code that assigns the new name to the blob.
$blobNewName = [System.IO.Path]::GetRandomFileName()
# Copy the blob from source container to new container with new name
Start-AzStorageBlobCopy -SrcContainer $containerName -SrcBlob $blobName.Name -DestContainer $newContainerName -DestBlob $blobNewName -Context $storageContext
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment