From 0beb24e10fea9aca3ac7f91486dc8bfdc21f4e0f Mon Sep 17 00:00:00 2001 From: Kris Borowinski Date: Fri, 7 Feb 2025 18:23:05 +0100 Subject: [PATCH] Fix `Start-Transcript` error when `$Transcript` is a `PSObject` wrapped string (#24963) --- .../host/msh/StartTranscriptCmdlet.cs | 2 +- .../Microsoft.Powershell.Host/Start-Transcript.Tests.ps1 | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Microsoft.PowerShell.ConsoleHost/host/msh/StartTranscriptCmdlet.cs b/src/Microsoft.PowerShell.ConsoleHost/host/msh/StartTranscriptCmdlet.cs index b220eae3bf..18725b5ddb 100644 --- a/src/Microsoft.PowerShell.ConsoleHost/host/msh/StartTranscriptCmdlet.cs +++ b/src/Microsoft.PowerShell.ConsoleHost/host/msh/StartTranscriptCmdlet.cs @@ -177,7 +177,7 @@ namespace Microsoft.PowerShell.Commands } else { - _outFilename = (string)value; + _outFilename = (string)PSObject.Base(value); } } diff --git a/test/powershell/Modules/Microsoft.Powershell.Host/Start-Transcript.Tests.ps1 b/test/powershell/Modules/Microsoft.Powershell.Host/Start-Transcript.Tests.ps1 index 3e398a0fa7..8e142c7655 100644 --- a/test/powershell/Modules/Microsoft.Powershell.Host/Start-Transcript.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.Powershell.Host/Start-Transcript.Tests.ps1 @@ -86,6 +86,11 @@ Describe "Start-Transcript, Stop-Transcript tests" -tags "CI" { $outputFilePath = Join-Path $TestDrive "PowerShell_transcript*" ValidateTranscription -scriptToExecute $script -outputFilePath $outputFilePath } + It "Should create Transcript file with 'Transcript' preference variable" { + # Casting to PSObject is necessary because Set-Variable does not automatically wrap the value in a PSObject + $script = "Set-Variable -Scope Global -Name Transcript -Value ([PSObject]'$transcriptFilePath'); Start-Transcript" + ValidateTranscription -scriptToExecute $script -outputFilePath $transcriptFilePath + } It "Should Append Transcript data in existing file if 'Append' parameter is used with Path parameter" { $script = "Start-Transcript -path $transcriptFilePath -Append" ValidateTranscription -scriptToExecute $script -outputFilePath $transcriptFilePath -append