Custom RoboCopy Progress Bar in PowerShell

后端 未结 7 995
夕颜
夕颜 2020-11-28 03:51

I\'m interested in a PowerShell script that copies a large amount of files from a server daily and I\'m interested in implementing a in-console progress bar like

7条回答
  •  無奈伤痛
    2020-11-28 04:24

    This is the code-snippet I finally used for such task:

    $fileName = 'test.txt'
    $fromDir  = 'c:\'
    $toDir    = 'd:\'
    
    $title = $null
    &robocopy "$fromDir" "$toDir" "$fileName" /z /mt /move /w:3 /r:10 /xo | %{
        $data = $_.Split("`t")
        if ($title -and $data[0] -match '\d+(?=%)') {
            Write-Progress $title -Status $data -PercentComplete $matches[0]
        }
        if($data[4]) {$title = $data[4]}
    }
    Write-Progress $title -complete
    

提交回复
热议问题