1
votes

I have Storage Account in Azure which contains files inside the folders. I want to move the .txt and .csv files from one folder to other folder in same Storage Account Container using PowerShell script.

So, can anyone suggest me how to do that?

3
It seems no direct method to move files, you need to copy first then delete them.Pamela Peng

3 Answers

0
votes

Please use azcopy in Powershell to acheive this.

azcopy login
azcopy copy 'https://<SourceStorageaccount>.blob.core.windows.net/<SourceContainer>/<SourceFile>' 'https://<DestinationStorageaccount>.blob.core.windows.net/<DestinationContainer>/<DestinationFile>'

The AzCopy command-line utility offers high-performance, scriptable data transfer for Azure Storage. You can use AzCopy to transfer data to and from Blob storage and Azure Files.

Alternatively, I think this can also be used:

Start-AzStorageBlobCopy -SrcBlob "SourceFolder/SourceFile" -SrcContainer "<SourceContainer>" -DestContainer "<DestinationContainer>" -DestBlob "DestinationFolder/DestinationFile"

At the moment, there seems to be no Powershell cmdlets in the Az.Storage module to move files. They would have to be copied to the destination and deleted from the source.

0
votes

Add the complete steps with Swishonary's reply:

$context = New-AzureStorageContext -StorageAccountName {accountName} -StorageAccountKey {Enter your storage account key here}
$Blobs = Get-AzStorageBlob -Container "SourceContainer" -Blob SourceFolder/*.csv -Context $context
foreach ($blob in $Blobs) {
    $blob.Name

    # Copy to DestinationFolder
    Start-AzStorageBlobCopy -SrcBlob "SourceFolder/SourceFile" -SrcContainer "<SourceContainer>" -DestContainer "<DestinationContainer>" -DestBlob "DestinationFolder/DestinationFile"

    # Delete the source blob
    Remove-AzStorageBlob -Container "SourceContainer" -Blob $blob.Name
}
0
votes

Adding more info to the above suggestion, the easiest way is to use Storage Explorer

This So thread provides some idea (PS) on your query.