Author Posts

October 15, 2015 at 8:34 am

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"

October 15, 2015 at 10:28 am

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.

October 15, 2015 at 11:24 am

Makes sense, thanks Don

October 16, 2015 at 6:24 am

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.

October 18, 2015 at 7:24 pm

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