PowerShell: Robocopy Broken
Prerequisites
- Write a descriptive title.
- Make sure you are able to repro it on the latest released version
- Search the existing issues.
- Refer to the FAQ.
- Refer to Differences between Windows PowerShell 5.1 and PowerShell.
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:
- 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
About this issue
- Original URL
- State: closed
- Created a year ago
- Reactions: 3
- Comments: 27 (15 by maintainers)
@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.This is indeed far from intuitive…
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.