Created
February 15, 2023 14:49
-
-
Save MauricioZa/b5d8c1645a82daef2d33eaaf9fc90136 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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