Reputation: 113
I have a powershell script that I am converting from running as a fore-front infinite while-loop to a scheduled task. The biggest problem here is that I would still like to maintain a log. Start-Transcript was the bit that did the logging previously, but that doesn't work with the background task.
These links (1, 2) show similar questions, but they only give the information that start-transcript won't work. They don't give any indication as to how it could be done.
Upvotes: 1
Views: 1261
Reputation: 200293
Basically you can do two things:
Add logging routines to your script (see for instance here).
Run the script like this:
powershell.exe -Command "&{your.ps1 *> your.log; exit $LASTEXITCODE}"
Personally I'd prefer the former, but it'd require more changes to your code.
Upvotes: 1