Other Languages - Powershell file write problem

Asked By Fraser on 12-Sep-11 10:45 AM

I have written a script in powershell to do some reporting on a DPM server. The script itself runs fine, but when I add "start-transcript $filename -append" it asks me "Are you sure you want to perform this action?" (then the rest of the standard text). I have added a -force option to the end of the command, but it still asks me the same question.

I have noticed this behavior with other commands that write files, is there a global variable that powershell uses to override -force and prompt for any disk writes? Is anyone able to make any suggestions as to what may be the issue here?


Ok, I've found out what the problem was - there is a global variable $ConfirmPreference, which confirms, well, the confirm preference - I did a "write-host $confirmpreference" and it was set to "Low", I then did a $confirmpreference="High" and this has resolved the issue.


Sri K replied to Fraser on 12-Oct-11 01:33 AM

Have you tried

 .\MyScript.ps1 2>&1 | tee -filePath c:\results.txt

2>&1 should be what you're looking for.