[英]How can I create a log of a powershell script running in the background?
I have a powershell script that I am converting from running as a fore-front infinite while-loop to a scheduled task.我有一个 powershell 脚本,我正在将其从作为前端无限循环运行转换为计划任务。 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.
Start-Transcript 是之前进行日志记录的部分,但这不适用于后台任务。
These links ( 1 , 2 ) show similar questions, but they only give the information that start-transcript won't work.这些链接 ( 1 , 2 ) 显示了类似的问题,但它们仅提供 start-transcript 不起作用的信息。 They don't give any indication as to how it could be done.
他们不给任何指示,以它如何做。
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.我个人更喜欢前者,但它需要对您的代码进行更多更改。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.