Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Start-Transcript: This host does not support transcription

Tags:

I want to start a transcript on a Windows Server 2008 R2

Start-Transcript -path C:\Temp\test.txt "Hello!" Stop-Transcript 

But PowerShell returns the following error message:

Start-Transcript : This host does not support transcription.

How it is possible to activate transcript?

like image 603
LaPhi Avatar asked Feb 17 '11 17:02

LaPhi


People also ask

How do I enable transcripts in PowerShell?

Enable PowerShell transcription by simply selecting the Enable option and clicking OK. You can also specify a transcript output folder if you would like one. If you opt to not specify an output directory, the PowerShell transcripts will be saved to the user's Documents folder.

How do I stop a PowerShell transcript?

To stop a transcript, use the Stop-Transcript cmdlet. To record an entire session, add the Start-Transcript command to your profile.


2 Answers

Windows PowerShell v4 ISE and lower do not support transcription. You must use the command line to run the commandlet.

From PowerShell v5 Start-Transcript is supported natively in ISE.

like image 91
Adam Prax Avatar answered Sep 23 '22 16:09

Adam Prax


COMPLETE ANSWER (PowerShell ISE 2.0/4.0)::

Having yet another look at this today on another server, I noticed that the latest PowerShell ISE (which also does not allow Start-Transcript) does not have an Output pane, and instead uses the new ConsolePane. Thus the function now is as follows:

Function Start-iseTranscript {   Param(    [string]$logname = (Get-logNameFromDate -path "C:\fso" -postfix " $(hostname)" -Create)   )   $transcriptHeader = @" ************************************** Windows PowerShell ISE Transcript Start Start Time: $((get-date).ToString('yyyyMMddhhmmss')) UserName: $env:username UserDomain: $env:USERDNSDOMAIN ComputerName: $env:COMPUTERNAME Windows version: $((Get-WmiObject win32_operatingsystem).version) ************************************** Transcript started. Output file is $logname "@  $transcriptHeader >> $logname  $psISE.CurrentPowerShellTab.Output.Text >> $logname    #Keep current Prompt   if ($Global:__promptDef -eq $null)   {     $Global:__promptDef =  (gci Function:Prompt).Definition     $promptDef = (gci Function:Prompt).Definition   } else   {     $promptDef = $Global:__promptDef   }    $newPromptDef = @'  if ($Host.Version.Major -eq 2) {   if ($Global:_LastText -ne $psISE.CurrentPowerShellTab.Output.Text)   {     Compare-Object -ReferenceObject ($Global:_LastText.Split("`n")) -DifferenceObject ($psISE.CurrentPowerShellTab.Output.Text.Split("`n"))|?{$_.SideIndicator -eq "=>"}|%{  $_.InputObject.TrimEnd()}|Out-File -FilePath ($Global:_DSTranscript) -Append     $Global:_LastText = $psISE.CurrentPowerShellTab.Output.Text   } } elseif ($Host.Version.Major -eq 4) {   if ($Global:_LastText -ne $psISE.CurrentPowerShellTab.ConsolePane.Text)   {     Compare-Object -ReferenceObject ($Global:_LastText.Split("`n")) -DifferenceObject ($psISE.CurrentPowerShellTab.ConsolePane.Text.Split("`n"))|?{$_.SideIndicator -eq "=>"}|%{  $_.InputObject.TrimEnd()}|Out-File -FilePath ($Global:_DSTranscript) -Append     $Global:_LastText = $psISE.CurrentPowerShellTab.ConsolePane.Text   } }  '@ + $promptDef   $Global:_LastText = $psISE.CurrentPowerShellTab.Output.Text   New-Item -Path Function: -Name "Global:Prompt" -Value ([ScriptBlock]::Create($newPromptDef)) -Force|Out-Null } 

Taking over the prompt is incredibly useful for this, however keeping two copies of the Output buffer is not ideal. I've also added in TrimEnd() as PSISE 2.0 likes to append spaces to fill the entire horizontal line width. Not sure if PSISE 4.0 does this too, but it's no problem now anyway.

NEW ANSWER (PowerShell ISE 2.0)::

I have just recently returned to this problem, and there is a way of forcing every update in PowerShell ISE to log out as a command is executed. This relies on the log path being saved in a Global Variable called _DSTranscript. This variable is passed to the Start-iseTranscript function. I have then Hijacked the Prompt function to execute a compare between _LastText and the hostUI Output Text, and append the differences out to the log. It now works a treat.

Function Start-iseTranscript {   Param(    [string]$logname = (Get-logNameFromDate -path "C:\fso" -postfix " $(hostname)" -Create)   )   $transcriptHeader = @" ************************************** Windows PowerShell ISE Transcript Start Start Time: $(get-date) UserName: $env:username UserDomain: $env:USERDNSDOMAIN ComputerName: $env:COMPUTERNAME Windows version: $((Get-WmiObject win32_operatingsystem).version) ************************************** Transcript started. Output file is $logname "@  $transcriptHeader >> $logname  $psISE.CurrentPowerShellTab.Output.Text >> $logname    #Keep current Prompt   if ($__promptDef -eq $null)   {     $__promptDef =  (gci Function:Prompt).Definition     $promptDef = (gci Function:Prompt).Definition   } else   {     $promptDef = $__promptDef   }    $newPromptDef = @' if ($global:_LastText -ne $psISE.CurrentPowerShellTab.Output.Text) {   Compare-Object -ReferenceObject $global:_LastText.Split("`n") -DifferenceObject $psISE.CurrentPowerShellTab.Output.Text.Split("`n")|?{$_.SideIndicator -eq "=>"}|%{ $_.InputObject.TrimEnd()}|Out-File -FilePath ($Global:_DSTranscript) -Append   $global:_LastText = $psISE.CurrentPowerShellTab.Output.Text } '@ + $promptDef    New-Item -Path Function: -Name "Global:Prompt" -Value ([ScriptBlock]::Create($newPromptDef)) -Force|Out-Null } 

ORIGINAL ANSWER::

PowerShell ISE does not natively support Transcription. There is a Scripting Guy blog about how to achieve this. Unfortunately this needs to be the last thing that is run in the script. This means that you need to remember to run it before closing the window. I wish this worked better, or there was a way to force it to run on window closure.

This is the function that produces close to the same result as the Start-Transcript feature:

Function Start-iseTranscript {   Param(     [string]$logname = (Get-logNameFromDate -path "C:\fso" -name "log" -Create)   )   $transcriptHeader = @" ************************************** Windows PowerShell ISE Transcript Start Start Time: $(get-date) UserName: $env:username UserDomain: $env:USERDNSDOMAIN ComputerName: $env:COMPUTERNAME Windows version: $((Get-WmiObject win32_operatingsystem).version) ************************************** Transcript started. Output file is $logname "@   $transcriptHeader >> $logname   $psISE.CurrentPowerShellTab.Output.Text >> $logname } #end function start-iseTranscript 
like image 43
8 revs Avatar answered Sep 21 '22 16:09

8 revs