Copy files between Containers in Azure Storage Account

There are some requirements sometimes to run a scheduled task to copy files between storage containers in same storage account or different storage account. To address this requirement, we need to run the relevant PowerShell script as a scheduled task. There are several ways available to run a scheduled task in azure. One of the method is based on Azure Function App. Create a Function App based on Runtime Stack as PowerShell Core as I have detailed the steps on how to achieve this with the help of an Azure Function app in my previous post here: https://www.cloudcompute.info/run-a-scheduled-task-in-azure/

Following PowerShell Script is useful for Copying files between Containers in Azure Storage Account

 $srcRGName = "name here"
 $srcStgAccount = "qrfree"
 $srcContainer = "source"
 $blobName = "source1/test.txt"
 $srcRGName = "name here"
 $destStgAccount = "qrfree"
 $destContainer = "archive"
 $srcStorageKey = Get-AzStorageAccountKey -Name $srcStgAccount -ResourceGroupName $srcRGName 
 $destStorageKey = Get-AzStorageAccountKey -Name $destStgAccount -ResourceGroupName $srcRGName
 $srcContext = New-AzStorageContext -StorageAccountName $srcStgAccount -StorageAccountKey $srcStorageKey.Value[0]
 $destContext = New-AzStorageContext -StorageAccountName $destStgAccount -StorageAccountKey $destStorageKey.Value[0]
 $copyOperation = Start-AzStorageBlobCopy -SrcBlob $blobName -SrcContainer $srcContainer -Context $srcContext -DestBlob $blobName -DestContainer $destContainer -DestContext $destContext -Force

Tags:

No responses yet

Leave a Reply

Your email address will not be published. Required fields are marked *

Recent Comments
Add External Contacts in Microsoft Teams