1

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.

Community
  • 1
  • 1
ncooper09
  • 113
  • 10

1 Answers1

1

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.

Community
  • 1
  • 1
Ansgar Wiechers
  • 193,178
  • 25
  • 254
  • 328
  • Thanks! I've been working on it for the last bit, and I've found a pretty good solution. I was hoping for something more automatic like Start-Transcript, but so it goes. I ended up using this guy's library, though a little modified. http://9to5it.com/powershell-logging-function-library/ – ncooper09 Oct 12 '16 at 19:41