X Tutup
The Wayback Machine - https://web.archive.org/web/20251012110947/https://github.com/PowerShell/PowerShell/issues/23949
Skip to content

Enter-PSSession doesn't work inside a function called from -Command argument #23949

@artemiux

Description

@artemiux

Prerequisites

Steps to reproduce

  1. Add to your $PROFILE:
function Enter-MyPSSession {
    Enter-PSSession -ComputerName (Read-Host 'Enter the computer name') -Credential (Get-Credential)
}
  1. Run pwsh -Command Enter-MyPSSession and then enter your actual remote computer and user name.

Expected behavior

Enter the computer name: your_computer

PowerShell credential request
Enter your credentials.
User: your_user
Password for user your_user: **************

[your_computer]: PS C:\Users\your_user\Documents>

Actual behavior

Enter the computer name: your_computer

PowerShell credential request
Enter your credentials.
User: your_user
Password for user your_user: **************

{Nothing happens. No errors. Keyboard doesn't respond even when you press Ctrl+C. Enter-MyPSSession works properly, if it isn't called from -Command argument.}

Error details

No response

Environment data

PS> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      7.4.2
PSEdition                      Core
GitCommitId                    7.4.2
OS                             Microsoft Windows 10.0.22631
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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      X Tutup