locked
HowTo: Copy Folder from One Azure FileShare to Another using Start-AzureStorageFileCopy? RRS feed

  • Question

  • I have been trying to copy a folder from one fileshare to another using Start-AzureStorageFileCopy without much luck.

    Maybe, it is something I am missing. 

    I have iterated to various parametersets: ShareName, ShareInstance, FileInstanceToFilePath. However, none of these seem to work.

    At present, I am using the following code:

    $srcstorageFiles = $srcFileShare | Get-AzureStorageFile
    foreach($storageFile in $srcstorageFiles){
        $srcCloudFileRef = $storageFile.GetFileReference($storageFile.name)
        
        $tgtStorageDir = Get-AzureStorageFile -ShareName $tgtFileShare.Name `
                            -Context $tgtStorageCtx -Path $storageFile.Name `
                            -ErrorAction SilentlyContinue
        if(-not $tgtStorageDir){
            $tgtStorageDir = New-AzureStorageDirectory -ShareName $tgtFileShare.Name `
                            -Path $storageFile.Name -Context $tgtStorageCtx 
        }
    
        $AzFileCopy = Start-AzureStorageFileCopy -SrcFile $srcCloudFileRef `
                        -DestShareName $tgtFileShare.Name `
                        -DestFilePath $tgtStorageDir.Name `
                        -DestContext $tgtStorageCtx -Verbose
        
        $AzFileCopy | Get-AzureStorageFileCopyState -WaitForComplete
    }


    Could you please let me know which parameter set we need to use for this?

    Monday, May 29, 2017 2:31 AM

All replies

  • Are you referring to copying files across Azure File Storage shares? If so, have you considered using the AzCopy command-line utility for file share copy. It is much easier using this tool since it is designed for copying data to and from Azure Blob, File and Table storage with optimal performance.
    The below command lets you copy across file shares.

    AzCopy /Source:https://myaccount1.file.core.windows.net/myfileshare1/ /Dest:https://myaccount2.file.core.windows.net/myfileshare2/ /SourceKey:key1 /DestKey:key2 /S

    -----------------------------------------------------------------------------------------------------

    Do click on "Mark as Answer" on the post that helps you, this can be beneficial to other community members.

    • Edited by Md Shihab Monday, May 29, 2017 9:57 AM
    • Proposed as answer by Md Shihab Thursday, June 1, 2017 10:28 AM
    Monday, May 29, 2017 9:56 AM