PowerShell: Robocopy Broken

Prerequisites

Steps to reproduce

PowerShell 7.4.0 Preview 1 Can no longer use robocopy.exe from powershell. As robocopy.exe returns status code other than 0 for successful copies.

Repro:

  1. robocopy .\PowerShell-7.4.0-preview.1-win-x64\ .\temp\

Expect: Runs without creating an error object.

Actual: Creates Error Object NativeCommandExitException: Program “Robocopy.exe” ended with non-zero exit code: 1.

Issue: This will break all of our existing automation. We use robocopy everywhere. And our scripts all use ErrorAction = Stop

Expected behavior

robocopy .\PowerShell-7.4.0-preview.1-win-x64\ .\temp\

# Files are copied. No error is raised when all files are copied.

Actual behavior

robocopy .\PowerShell-7.4.0-preview.1-win-x64\ .\temp\
 # An error is raised even though robocopy detected no errors.
 # 1 indicates all files copied.

Error details

PS > Get-Error

Exception             :
    Type        : System.Management.Automation.NativeCommandExitException
    Path        : C:\Windows\system32\Robocopy.exe
    ExitCode    : 1
    ProcessId   : 17460
    ErrorRecord :
        Exception             :
            Type    : System.Management.Automation.ParentContainsErrorRecordException
            Message : Program "Robocopy.exe" ended with non-zero exit code: 1.
            HResult : -2146233087
        CategoryInfo          : NotSpecified: (:) [], ParentContainsErrorRecordException
        FullyQualifiedErrorId : ProgramExitedWithNonZeroCode
    Message     : Program "Robocopy.exe" ended with non-zero exit code: 1.
    HResult     : -2146233087
TargetObject          : C:\Windows\system32\Robocopy.exe
CategoryInfo          : NotSpecified: (C:\Windows\system32\Robocopy.exe:String) [], NativeCommandExitException
FullyQualifiedErrorId : ProgramExitedWithNonZeroCode

Environment data

$PSVersionTable

Name                           Value
----                           -----
PSVersion                      7.4.0-preview.1
PSEdition                      Core
GitCommitId                    7.4.0-preview.1
OS                             Microsoft Windows 10.0.22621
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Visuals

Steps.zip

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Reactions: 3
  • Comments: 27 (15 by maintainers)

Most upvoted comments

@jazzdelightsme I believe it was mentioned in a separate issue that $PSNativeCommandUseErrorActionPreference is default to $false and only set to $true in 7.4 previews to get feedback.

@sba923, the current behavior is a bit counter-intuitive:

This is indeed far from intuitive…

Discussion in the team we agree that this feature is working as expected and we don’t want to special case robocopy. Instead, I’ve opened a doc bug to ensure we have a good example for cases like robocopy to turn it off and on.

Hang on… I didn’t see a response to mklement’s request for confirmation that we would still have existing behavior in release versions. Your statement, @SteveL-MSFT almost sounds like “no, we are turning this on, and doc’ing it better”. If that is the case, please allow me to respectfully scream “bloody murder”. I’ve already gotten bug reports from users of my modules for robocopy, and git, and I can’t even remember what else. I assumed this was so clearly such a massively breaking change that it surely wouldn’t stand…

Please see the following proposal for a possible solution:

The reason for not setting it back is that it never should have been enabled. Old scripts that we have are well tested and check $LASTEXITCODE where necessary.