I have a PowerShell script that uses du.exe (Disk Usage originally from Sysinternals) to calculate the size of directories.
If I run du c:\Backup in the console, it works as expected, but the same line of code run in ISE or PowerGui gives the expected result plus the error
+ du <<<< c:\backup
+ CategoryInfo : NotSpecified: (:String) [], RemoteException
+ FullyQualifiedErrorId : NativeCommandError
Why is that? How do I avoid this error? I tried invoke-expression, using &, but no go.
Thanks for the help.
$ErrorActionPreferenceset toStopthis will actually stop your script's execution. My solution was to set it toContinue, invoke the command, and set it back toStop.$ErrorActionPreference = 'Continue'fixed the problemstderr. Some native commands usestderras a verbose output stream, which can be redirected to/dev/nullornulby the user if they are not interested in the verbose output. A PowerShell host should check the exit code of the native command to decide if output onstderrshould be interpreted as aNativeCommandErroror not. But regardless, in PowerShell,stderroutput will be wrapped in anErrorRecord, that's just how it is.