When running a simple PowerShell script from Task Scheduler, I would like to redirect the output to a file.
There is a long thread about this very topic here, yet i
It would be maybe easier to use Start-Transcript in order to log directly to a file:
# Get script name
$ScriptFullPath = $MyInvocation.MyCommand.Path
# Start logging stdout and stderr to file
Start-Transcript -Path "$ScriptFullPath.log" -Append
[Some PowerShell commands]
# Stop logging to file
Stop-Transcript
The log file will be in the same directory as the script.