使用内部进度条

1..10 | foreach-object {
        $fileName = "file_name_$_.txt"
        Write-Progress -Activity "Copying files" -Status "$($_*10) %" -Id 1 -PercentComplete ($_*10) -CurrentOperation "Copying file $fileName"
            
        1..100 | foreach-object {
            Write-Progress -Activity "Copying contents of the file $fileName" -Status "$_ %" -Id 2 -ParentId 1 -PercentComplete $_ -CurrentOperation "Copying $_. line"
            
            Start-Sleep -Milliseconds 20 # sleep simulates working code, replace this line with your executive code (i.e. file copying)
        }

        Start-Sleep -Milliseconds 500 # sleep simulates working code, replace this line with your executive code (i.e. file search)

   }

请注意,为简洁起见,此示例不包含任何执行代码(使用 Start-Sleep 模拟)。但是,可以直接运行它,而不是修改和使用它。

这是 PS 控制台中的结果: StackOverflow 文档

这是 PS ISE 中的结果: StackOverflow 文档