I'm running Windows Server 2008 Enterprise x64 R2.
Sample script x.ps1:
(Get-Date).DateTimeWrite-Output "output"
Write-Warning "warning"
Write-Error "error"
Run this in the cmd console:
powershell -command ".\x.ps1" *> x.log. Works like a charm, I've got a log.
Now delete x.log. Create a scheduled task with the exact same command: powershell -command ".\x.ps1" *> x.log. Run the scheduled task. No log.
WTF? How hard should this be? I've spent hours Googling, I know this problem comes up a lot. Why is a scheduled task so different than running from a cmd console?
I also tried powershell -file, as well as Start-Transcript, which looked promising, but I don't like the line wrapping in the scheduled task output.