Enter-PSSession with VMName gives cast error · Issue #24014 · PowerShell/PowerShell · GitHub
Skip to content

Enter-PSSession with VMName gives cast error #24014

@nils-trustnode

Description

@nils-trustnode

Prerequisites

Steps to reproduce

Enter-PSSession -VMName 'testvm' -Credential $credential ends with an error message. Changing the VMName or omit the Credential flag doesn't fix it.

Expected behavior

Shell into guest vm

Actual behavior

Error: "Enter-PSSession: Unable to cast object of type 'System.String' to type 'VMState'."

Error details

Exception             :
    Type       : System.InvalidCastException
    TargetSite :
        Name          : GetRunspaceForVMSession
        DeclaringType : [Microsoft.PowerShell.Commands.EnterPSSessionCommand]
        MemberType    : Method
        Module        : System.Management.Automation.dll
    Message    : Unable to cast object of type 'System.String' to type 'VMState'.
    Source     : System.Management.Automation
    HResult    : -2147467262
    StackTrace :
   at Microsoft.PowerShell.Commands.EnterPSSessionCommand.GetRunspaceForVMSession()
   at Microsoft.PowerShell.Commands.EnterPSSessionCommand.ProcessRecord()
   at System.Management.Automation.CommandProcessor.ProcessRecord()
CategoryInfo          : NotSpecified: (:) [Enter-PSSession], InvalidCastException
FullyQualifiedErrorId : System.InvalidCastException,Microsoft.PowerShell.Commands.EnterPSSessionCommand
InvocationInfo        :
    MyCommand        : Enter-PSSession
    ScriptLineNumber : 1
    OffsetInLine     : 1
    HistoryId        : 9
    Line             : Enter-PSSession -VMName 'testvm' -Credential $credential
    Statement        : Enter-PSSession -VMName 'testvm' -Credential $credential
    PositionMessage  : At line:1 char:1
                       + Enter-PSSession -VMName 'testvm' -Credential $credential
                       + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    InvocationName   : Enter-PSSession
    CommandOrigin    : Internal
ScriptStackTrace      : at <ScriptBlock>, <No file>: line 1

Environment data

PSVersion                      7.4.3
PSEdition                      Core
GitCommitId                    7.4.3
OS                             Microsoft Windows 10.0.14393
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

Metadata

Metadata

Assignees

No one assigned

    Labels

    In-PRIndicates that a PR is out for the issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions