Newbie question about log files
I've been using POSH-ACME for several years and think it's great - thanks! I've recently had to change DNS providers to Cloudflare and thus change the plugin, which also work fine with their API key.
I run the PS script on a Windows server box using Task Scheduler and that too works fine...but...
If I run the script in a PS window I can see what's happening but as far as I can see, under Task Scheduler it either runs fine or dies. So daft question, I can't see any way to create / capture log file from a scheduled PowerShell task.
Any hints anyone?.. TiA
How is the Action in your task defined right now?
Personally for PowerShell stuff in general in Task Scheduler I like this basic template.
- Program/script:
pwsh.exe(or powershell.exe if you're using legacy) - Start in:
<path to working directory>(can be empty if what you're running doesn't use relative paths) - Add arguments:
-C "<whatever code/command you'd normally run> *> .\MyTask.log; exit $LASTEXITCODE"
The *> .\MyTask.log; basically redirects all of the enabled output streams to a file. So for Posh-ACME, that would normally be -Verbose unless you've enabled debug logging as well.
The exit $LASTEXITCODE is a trick to make it more obvious if your running powershell code actually has an error or not. Without it, even if your code has an error, the PowerShell process will exit as if nothing is wrong and Task Scheduler will report the task completed successfully.
If you want something a little more formal, there's also Start-Transcript instead of the output redirection.
Thanks for the helpful reply - I'll try it & revert.