8000 Fix `Start-Transcript` error when `$Transcript` is a `PSObject` wrapp… · PowerShell/PowerShell@0beb24e · GitHub
[go: up one dir, main page]

Skip to content

Commit 0beb24e

Browse files
authored
Fix Start-Transcript error when $Transcript is a PSObject wrapped string (#24963)
1 parent 1790f3a commit 0beb24e

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

src/Microsoft.PowerShell.ConsoleHost/host/msh/StartTranscriptCmdlet.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ protected override void BeginProcessing()
177177
}
178178
else
179179
{
180-
_outFilename = (string)value;
180+
_outFilename = (string)PSObject.Base(value);
181181
}
182182
}
183183

test/powershell/Modules/Microsoft.Powershell.Host/Start-Transcript.Tests.ps1

+5
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,11 @@ Describe "Start-Transcript, Stop-Transcript tests" -tags "CI" {
8686
$outputFilePath = Join-Path $TestDrive "PowerShell_transcript*"
8787
ValidateTranscription -scriptToExecute $script -outputFilePath $outputFilePath
8888
}
89+
It "Should create Transcript file with 'Transcript' preference variable" {
90+
# Casting to PSObject is necessary because Set-Variable does not automatically wrap the value in a PSObject
91+
$script = "Set-Variable -Scope Global -Name Transcript -Value ([PSObject]'$transcriptFilePath'); Start-Transcript"
92+
ValidateTranscription -scriptToExecute $script -outputFilePath $transcriptFilePath
93+
}
8994
It "Should Append Transcript data in existing file if 'Append' parameter is used with Path parameter" {
9095
$script = "Start-Transcript -path $transcriptFilePath -Append"
9196
ValidateTranscription -scriptToExecute $script -outputFilePath $transcriptFilePath -append

0 commit comments

Comments
 (0)
0