Outputting all output from a scheduled psm1 to a file?

I have a psm1 which is called from a scheduled task that happens around midnight. At this point I’m still developing it and I just want to read everything that’s happening(getting backups, zipping things, moving things etc…)

Is there a way I can basically do what this pseudo code is saying?

Task scheduler calls test.bat which contains:

PowerShell.exe -Command “& ‘TestScript’” >2&1 | “C:\backup\whats_going_on.txt”

First, you can do almost exactly that pseudo-code. But it depends on how the script is outputting its text. Anything done with Write-Host, no, you can’t redirect or capture. Write-AnhythingElse, yes. Write-Verbose, for example, provided you’ve enabled verbose output.

Makes sense, thanks Don

Close with the redirection… but not quite.
PowerShell.exe c:\scripts\test.ps1 > “C:\backup\whats_going_on.txt” 2>&1

Also, check out Start-Transcript - it’s pretty handy.

If you have any issues with formatting try | out-string, this has come in handy for me a few times.