Azure Functions
An Azure service that provides an event-driven serverless compute platform.
5,114 questions
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Hello team,
I am experiencing issues with a PowerShell script that copies files from one blob container to another. Specifically, I am trying to run this script from a function app. Can anyone assist me in resolving this issue?
Hello @sai pavan ,
Unfortunately, the script you mentioned is missing in your message. However, I am sharing the script I used to copy files from one blob container to another.
# Import the Azure PowerShell module
Import-Module Az
# Define the storage account and containers
$sourceStorageAccount = "your-source-storage-account"
$sourceContainer = "source-container"
$destinationStorageAccount = "your-destination-storage-account"
$destinationContainer = "destination-container"
$resourceGroup = "your-resource-group"
# Authenticate to Azure
Connect-AzAccount
# Retrieve the source and destination storage account keys
$sourceStorageKey = (Get-AzStorageAccountKey -ResourceGroupName $resourceGroup -Name $sourceStorageAccount).Value[0]
$destinationStorageKey = (Get-AzStorageAccountKey -ResourceGroupName $resourceGroup -Name $destinationStorageAccount).Value[0]
# Create storage context for source and destination
$sourceContext = New-AzStorageContext -StorageAccountName $sourceStorageAccount -StorageAccountKey $sourceStorageKey
$destinationContext = New-AzStorageContext -StorageAccountName $destinationStorageAccount -StorageAccountKey $destinationStorageKey
# List blobs in the source container
$blobs = Get-AzStorageBlob -Container $sourceContainer -Context $sourceContext
# Copy each blob to the destination container
foreach ($blob in $blobs) {
$sourceUri = $blob.ICloudBlob.Uri.AbsoluteUri
$destinationBlob = Start-AzStorageBlobCopy -AbsoluteUri $sourceUri -DestContainer $destinationContainer -DestContext $destinationContext
Write-Output "Copying blob: $($blob.Name) to $($destinationContainer)"
}
Write-Output "Blob copy completed."
Don't forget to mark my reply as the answer if it resolves your issue.
Regards,
Amol Shelar