I would do:
Create a function to call your script and redirect the output of this function like this:
.ps1:
function test{
# Your simple script commands
ls c:\temp -Filter *.JPG
ls z:\ # Non-existent directory
}
test *> c:\temp\log.txt
Here is the log file:
Répertoire : C:\temp
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a--- 07/06/2008 11:06 176275 HPIM1427.JPG
-a--- 07/06/2008 11:06 69091 HPIM1428.JPG
-a--- 07/06/2008 11:06 174661 HPIM1429.JPG
ls : Lecteur introuvable. Il n'existe aucun lecteur nommé « z ».
Au caractère C:\temp\test.ps1:14 : 1
+ ls z:\ #non existent dir
+ ~~~~~~
+ CategoryInfo : ObjectNotFound: (z:String) [Get-ChildItem], Driv
eNotFoundException
+ FullyQualifiedErrorId : DriveNotFound,Microsoft.PowerShell.Commands.GetC
hildItemCommand
You can control what do you want to output with the new V3 redirection operators:
Do-Something 3> warning.txt # Writes warning output to warning.txt
Do-Something 4>> verbose.txt # Appends verbose.txt with the verbose output
Do-Something 5>&1 # Writes debug output to the output stream
Do-Something *> out.txt # Redirects all streams (output, error, warning, verbose, and debug) to out.txt