I want to bulk insert from blob-to-blob. where I am having files names text files

2025-06-09T13:03:09.8966667+00:00
function Copy-AzureBlobWithFileList {
    param (
        [string]$SourcePath,     # e.g. https://account.blob.core.windows.net/container/folder?SAS
        [string]$DestPath,       # e.g. https://account.blob.core.windows.net/container2/folder?SAS
        [string]$FileListPath, # e.g. "CR121.PDF;CR234.PDF" or path to a file
        [string]$PeriodYear      # just used for naming the include file
    )

    $includeFilePath = "D:\CRS1-841\StagingFolder\$PeriodYear.txt"
    $folder = Split-Path $includeFilePath

    if (-not (Test-Path $folder)) {
        New-Item -ItemType Directory -Path $folder | Out-Null
    }

    # Decide if $FileListString is a file path or semicolon separated list
    if (Test-Path $FileListPath) {
        # It's a path to a file
        $fileNames = Get-Content -Path $FileListPath | ForEach-Object { $_.Trim() }
    } else {
        # It's a string with filenames separated by ;
        $fileNames = $FileListPath -split ';' | ForEach-Object { $_.Trim() }
    }

    # Write the filtered list to include file
    $fileNames | Set-Content -Encoding UTF8 -Path $includeFilePath

    $args = @(
        "copy",
        $SourcePath,
        $DestPath,
        "--include-path=$includeFilePath",
        "--recursive=true",
        "--overwrite=ifSourceNewer"
    )

    Write-Output "Running azcopy $($args -join ' ')"
    Start-Process -FilePath "azcopy" -ArgumentList $args -NoNewWindow -Wait
}
Windows for business Windows Server User experience PowerShell
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.