简体   繁体   English

Powershell 启动脚本错误

[英]Powershell start transcript error

I am running a powershell script from a batch file:我正在从批处理文件运行 powershell 脚本:

try {
  Start-Transcript -path ("C:\PS\Logs\XXXX_Session_QA_" + (Get-Date).tostring("yyyyMMdd-hhmmss-tt") + ".txt")

  <Rest of the Code>
}
catch {
  stop-transcript
}

Every time I run the script, I see the error每次运行脚本时,我都会看到错误

Error: Transcription has not been started.错误:转录尚未开始。 Use the start-transcript command to start transcription.使用 start-transcript 命令开始转录。

I have gone through some or most of the previous posts and the code should work but it isn't triggering at all.我已经阅读了之前的部分或大部分帖子,代码应该可以工作,但根本没有触发。 The initial log file isn't being created either.也没有创建初始日志文件。 Any idea why this could be happening or any help here?知道为什么会发生这种情况或有任何帮助吗?

Does the folder structure exist for where you are trying to write the transcript to?您尝试将成绩单写入的位置是否存在文件夹结构? According to the documentation, it is required (see italics below):根据文档,它是必需的(参见下面的斜体):

-Path -小路

Specifies a location for the transcript file.指定脚本文件的位置。 Enter a path to a .txt file.输入 .txt 文件的路径。 Wildcards are not permitted.不允许使用通配符。 If you do not specify a path, Start-Transcript uses the path in the value of the $Transcript global variable.如果不指定路径,Start-Transcript 将使用 $Transcript 全局变量值中的路径。 If you have not created this variable, Start-Transcript stores the transcripts in the $Home\\My Documents directory as \\PowerShell_transcript..txt files.如果您尚未创建此变量,Start-Transcript 会将脚本作为 \\PowerShell_transcript..txt 文件存储在 $Home\\My Documents 目录中。

If any of the directories in the path do not exist, the command fails.如果路径中的任何目录不存在,则命令失败。

https://technet.microsoft.com/library/05b8f72c-ae3b-45d5-95e0-86aa1ca1908a(v=wps.630).aspx https://technet.microsoft.com/library/05b8f72c-ae3b-45d5-95e0-86aa1ca1908a(v=wps.630).aspx

You will also need permission to write to that path of course.当然,您还需要获得写入该路径的权限。

So... if the Start-Transcript cmdlet is throwing an error, you are then catching it in the catch{} block (invisibly) which then executes the Stop-Transcript .所以...如果 Start-Transcript cmdlet 抛出错误,那么您将在catch{}块(不可见)中捕获它,然后执行Stop-Transcript

This presumably is what is actually causing the error message: the net result is that you are trying to stop transcription when it never started in the first place.这大概是导致错误消息的实际原因:最终结果是您试图在转录从未开始时停止转录。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM