powershell - 如何检查成绩单是否正在运行? [英] powershell - how to check if transcript is running?
本文介绍了powershell - 如何检查成绩单是否正在运行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
每次我的脚本没有正确结束并且停止转录没有执行时,我都会收到这条消息:
I get this message everytime my script doesn't end properly and stop-transcript is not executed:
Start-Transcript : Transcription has already been started. Use the stop-transcr
ipt command to stop transcription.
At C:\ps\003desifrovanie.ps1:4 char:17
+ start-transcript <<<< -path c:\_LOG\sfrbdesifrovanie.log -append
+ CategoryInfo : NotSpecified: (:) [Start-Transcript], InvalidOpe
rationException
+ FullyQualifiedErrorId : System.InvalidOperationException,Microsoft.Power
Shell.Commands.StartTranscriptCommand
是否可以检查脚本是否正在运行并在脚本开始时使用 if-then 停止它?或者如何在最后可靠地阻止它?谢谢
Is it possible to check if transcript is running and stop it with if-then at start of the script? Or how to reliably stop it at the end? Thank you
推荐答案
在你的 powershell 脚本的开头添加一个空的 try-catch
块来停止转录怎么样?
What about an empty try-catch
block at the beginning of your powershell script to stop transcribing?
try{
stop-transcript|out-null
}
catch [System.InvalidOperationException]{}
这篇关于powershell - 如何检查成绩单是否正在运行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文