2

I am using DU.exe in Powershell script to capture the size of a remote folder, code as below:

$Duexe ="c:\du\du.exe"

$unc = "\\$server\$Letter$\$Name"

write-host "Processing:  " $unc

$stuff =  du -q "\\$server\$Letter$\$Name" 2>&1 

$formated = $stuff | Format-Table -auto

write-host $stuff

I have to redirect the stderror to stop an error caused by the "-q" switch. However the output contians following error:

System.Management.Automation.RemoteException

In context:

Files:        290215 Directories:  2246 Size:         128,529,542,967 bytes Size on disk: 128,529,542,967 bytes  System.Management.Automation.RemoteException 

Why is this? If I run du outside powershell I get no errors on the same unc paths.

1
  • I have just found out if I trun of the stderror redirect it does nto display the messgae howevere it does display: Commented Feb 18, 2011 at 12:24

2 Answers 2

2

You didn't so much stop the error as "redirect" the error to the output stream which you captured in the variable $stuff. Try redirecting just the error stream to $null to ignore it:

$stuff =  du -q "\\$server\$Letter$\$Name" 2> $null

$stuff | Format-Table -auto

BTW, you don't need to write-host the "formatted" stuff. Format-Table will output to the host automatically.

Sign up to request clarification or add additional context in comments.

Comments

1

You don't redirect output in Powershell with Batch style >. Just use $stuff = du -q $unc to get the du output into a variable.

By the way, you print $stuff but set formatted content into $formated. Is this intended?

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.