Vibhav MS
Vibhav MS

Reputation: 163

Powershell start transcript error

I am running a powershell script from a batch file:

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.

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?

Upvotes: 2

Views: 3425

Answers (2)

Nick Green
Nick Green

Reputation: 121

Make sure you have access to the path you are trying to write to. In my case the path on the C:\ drive I was trying to write to was restricted to the user I was running the script as.

Upvotes: 0

MisterSeajay
MisterSeajay

Reputation: 4659

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. Wildcards are not permitted. If you do not specify a path, Start-Transcript uses the path in the value of the $Transcript global variable. If you have not created this variable, Start-Transcript stores the transcripts in the $Home\My Documents directory as \PowerShell_transcript..txt files.

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

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.

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.

Upvotes: 3

Related Questions