@@ -35,8 +35,12 @@ $writer = New-Object System.IO.StreamWriter($stdout, $utf8)
3535# All subsequent output must be written using [System.Console]::WriteLine(). In
3636# PowerShell 4, Write-Host and Out-Default do not consider the updated stream writer.
3737
38- # Print the ##command.
39- [System.Console ]::WriteLine(" ##[command]robocopy.exe /E /COPY:DA /NP /R:3 /MT:$ParallelCount `" $Source `" `" $Target `" *" )
38+ # Print the ##command. The /MT parameter is only supported on 2008 R2 and higher.
39+ if ($ParallelCount -gt 1 ) {
40+ [System.Console ]::WriteLine(" ##[command]robocopy.exe /E /COPY:DA /NP /R:3 /MT:$ParallelCount `" $Source `" `" $Target `" *" )
41+ } else {
42+ [System.Console ]::WriteLine(" ##[command]robocopy.exe /E /COPY:DA /NP /R:3 `" $Source `" `" $Target `" *" )
43+ }
4044
4145# The $OutputEncoding variable instructs PowerShell how to interpret the output
4246# from the external command.
@@ -59,15 +63,30 @@ $OutputEncoding = [System.Text.Encoding]::Default
5963#
6064# Note, the output from robocopy needs to be iterated over. Otherwise PowerShell.exe
6165# will launch the external command in such a way that it inherits the streams.
62- & robocopy.exe / E / COPY:DA / NP / R:3 / MT:$ParallelCount $Source $Target * 2>&1 |
63- ForEach-Object {
64- if ($_ -is [System.Management.Automation.ErrorRecord ]) {
65- [System.Console ]::WriteLine($_.Exception.Message )
66+ #
67+ # Note, the /MT parameter is only supported on 2008 R2 and higher.
68+ if ($ParallelCount -gt 1 ) {
69+ & robocopy.exe / E / COPY:DA / NP / R:3 / MT:$ParallelCount $Source $Target * 2>&1 |
70+ ForEach-Object {
71+ if ($_ -is [System.Management.Automation.ErrorRecord ]) {
72+ [System.Console ]::WriteLine($_.Exception.Message )
73+ }
74+ else {
75+ [System.Console ]::WriteLine($_ )
76+ }
6677 }
67- else {
68- [System.Console ]::WriteLine($_ )
78+ } else {
79+ & robocopy.exe / E / COPY:DA / NP / R:3 $Source $Target * 2>&1 |
80+ ForEach-Object {
81+ if ($_ -is [System.Management.Automation.ErrorRecord ]) {
82+ [System.Console ]::WriteLine($_.Exception.Message )
83+ }
84+ else {
85+ [System.Console ]::WriteLine($_ )
86+ }
6987 }
70- }
88+ }
89+
7190[System.Console ]::WriteLine(" ##[debug]robocopy exit code '$LASTEXITCODE '" )
7291[System.Console ]::Out.Flush()
7392if ($LASTEXITCODE -ge 8 ) {
0 commit comments