Thursday, May 12, 2016

out-file

out-file is brilliant.  It is so helpful to get stuff out into txt files both for logging what has happened but also for helping you during the script design to understand what is  going on.

The best why to do it is to create a the variable which specifies the output file name.  You can even use variables to create the variable which can be very useful.

During testing it is useful to write stuff out to public which is always successful regardless of the user context the script is running it.


$OutputFile = $env:PUBLIC+"\Documents\"+$AnotherVar+".txt"

command | out-file $OutputFile