Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Start-Transcript throws when $Transcript is a PSObject wrapped string #24740

Copy link
Copy link
@billkindle

Description

@billkindle
Issue body actions

Prerequisites

Steps to reproduce

First bug report I've filed for PowerShell ever, so go easy on me :-). Here's the PowerShell doc's Github issue I had raised that is now closed with the suggestion of filing a bug report.

I believe I've stumbled upon a bug with Start-Transcript when using one of the Start-Transcript examples when using preference variables in PowerShell 7.4.6 (on Windows and Linux) when using '~' in the path.

Using Start-Transcript after using the example #3 in the docs, I get an error:

Start-Transcript: Unable to cast object of type 'Systme.Management.Automation.PSObject' to type 'System.String'.

However, if I use Start-Transcript $Trasncript, the command works and a transcript is created without issue. I do not get this error using the example with a UNC path or full local path. It seems to only happen when using '~' in both Windows and Linux.

Expected behavior

$sharepath  = '~/PowerShell_Transcripts/'
$username   = $env:USERNAME
$hostname   = hostname
$version    = $PSVersionTable.PSVersion.ToString()
$datetime   = Get-Date -f 'yyyyMMddHHmmss'
$filename   = "Transcript-${username}-${hostname}-${version}-${datetime}.txt"
$Transcript = Join-Path -Path $sharepath -ChildPath $filename
Start-Transcript # I should see "Transcript Started, output file $filename here"

Actual behavior

$sharepath  = '~/PowerShell_Transcripts/'
$username   = $env:USERNAME
$hostname   = hostname
$version    = $PSVersionTable.PSVersion.ToString()
$datetime   = Get-Date -f 'yyyyMMddHHmmss'
$filename   = "Transcript-${username}-${hostname}-${version}-${datetime}.txt"
$Transcript = Join-Path -Path $sharepath -ChildPath $filename
Start-Transcript
Start-Transcript: Unable to cast object of type 'System.Management.Automation.PSObject' to type 'System.String'.

Error details

Exception             : 
    Type       : System.InvalidCastException
    TargetSite : 
        Name          : ChkCast_Helper
        DeclaringType : [System.Runtime.CompilerServices.CastHelpers]
        MemberType    : Method
        Module        : System.Private.CoreLib.dll
    Message    : Unable to cast object of type 'System.Management.Automation.PSObject' to type 'System.String'.
    Source     : System.Private.CoreLib
    HResult    : -2147467262
    StackTrace : 
   at Microsoft.PowerShell.Commands.StartTranscriptCommand.BeginProcessing()
   at System.Management.Automation.Cmdlet.DoBeginProcessing()
   at System.Management.Automation.CommandProcessorBase.DoBegin()
CategoryInfo          : NotSpecified: (:) [Start-Transcript], InvalidCastException
FullyQualifiedErrorId : System.InvalidCastException,Microsoft.PowerShell.Commands.StartTranscriptCommand
InvocationInfo        : 
    MyCommand        : Start-Transcript
    ScriptLineNumber : 1
    OffsetInLine     : 1
    HistoryId        : 13
    Line             : Start-Transcript
    Statement        : Start-Transcript
    PositionMessage  : At line:1 char:1
                       + Start-Transcript
                       + ~~~~~~~~~~~~~~~~
    InvocationName   : Start-Transcript
    CommandOrigin    : Internal
ScriptStackTrace      : at <ScriptBlock>, <No file>: line 1

Environment data

Name                           Value
----                           -----
PSVersion                      7.4.6
PSEdition                      Core
GitCommitId                    7.4.6
OS                             Fedora Linux 41 (Workstation Edition)
Platform                       Unix
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Name                           Value
----                           -----
PSVersion                      7.4.6
PSEdition                      Core
GitCommitId                    7.4.6
OS                             Microsoft Windows 10.0.26100
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Visuals

No response

Reactions are currently unavailable

Metadata

Metadata

Assignees

No one assigned

    Labels

    In-PRIndicates that a PR is out for the issueIndicates that a PR is out for the issueIssue-BugIssue has been identified as a bug in the productIssue has been identified as a bug in the productUp-for-GrabsUp-for-grabs issues are not high priorities, and may be opportunities for external contributorsUp-for-grabs issues are not high priorities, and may be opportunities for external contributors

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.