Skip to content

Get-Credential throws exception instead of prompting for input in PowerShell 5.1 #3820

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
5 tasks done
csandfeld opened this issue Feb 10, 2022 · 13 comments · Fixed by #3847
Closed
5 tasks done

Get-Credential throws exception instead of prompting for input in PowerShell 5.1 #3820

csandfeld opened this issue Feb 10, 2022 · 13 comments · Fixed by #3847
Labels
Area-Extension Terminal Bug: PowerShell 5.1 Bugs when using PowerShell 5.1. Bug: Pre-release Bugs reproducing only in the pre-release extension. Issue-Bug A bug to squash.

Comments

@csandfeld
Copy link

csandfeld commented Feb 10, 2022

Prerequisites

  • I have written a descriptive issue title.
  • I have searched all issues to ensure it has not already been reported.
  • I have read the troubleshooting guide.
  • I am sure this issue is with the extension itself and does not reproduce in a standalone PowerShell instance.
  • I have verified that I am using the latest version of Visual Studio Code and the PowerShell extension.

Summary

When using preview v2022.2.0 with Windows PowerShell 5.1, this exception is throw in the integrated console when running Get-Credential.

PS C:\> Get-Credential
Get-Credential : Cannot process command because of one or more missing mandatory parameters: Credential.
At line:1 char:1
+ Get-Credential
+ ~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [Get-Credential], ParameterBindingException
    + FullyQualifiedErrorId : MissingMandatoryParameter,Microsoft.PowerShell.Commands.GetCredentialCommand
 
PS C:\> 

This is not the case when using PowerShell Extension v2021.12.0, or when using PowerShell 7.2.1 instead of Windows PowerShell.

PowerShell Version

PS C:\> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      5.1.19041.1320
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.19041.1320
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1

Visual Studio Code Version

PS C:\> code --version
1.64.1
d6ee99e4c045a6716e5c653d7da8e9ae6f5a8b03
x64
PS C:\>

Extension Version

PS C:\> code --list-extensions --show-versions                           
[email protected]
[email protected]
PS C:\>

Steps to Reproduce

  • Open Visual Studio Code
  • Install PowerShell Preview extension
  • Configure integrated console to use Windows PowerShell x64
  • Run Get-Credential (either directly in console, or by pressing F8 - makes no difference)

Visuals

No response

Logs

No response

@csandfeld csandfeld added the Issue-Bug A bug to squash. label Feb 10, 2022
@ghost ghost added the Needs: Triage Maintainer attention needed! label Feb 10, 2022
@JustinGrote
Copy link
Collaborator

I can't reproduce:
image

@JustinGrote JustinGrote added Needs: Repro Info 🤔 and removed Needs: Triage Maintainer attention needed! labels Feb 16, 2022
@csandfeld
Copy link
Author

csandfeld commented Feb 17, 2022

Try just Get-Credential (without the -Message 'ok' param)

image

@csandfeld
Copy link
Author

Same test as above with v2021.12.0

image

@andyleejordan andyleejordan added the Bug: Pre-release Bugs reproducing only in the pre-release extension. label Feb 17, 2022
@andyleejordan andyleejordan moved this to Todo in Sea Biscuit Feb 17, 2022
@csandfeld
Copy link
Author

Is further repro info needed?

@JustinGrote
Copy link
Collaborator

@csandfeld so I can repro it as you state, not sure why Get-Credential would have its parameters parsed differently in the PSIC than in regular console. @andschwa @SeeminglyScience any ideas?

@JustinGrote
Copy link
Collaborator

I noticed that the Credential parameter is flagged mandatory in 5.1, but it doesn't follow the usual behavior of showing the mandatory parameter error, instead it hooks into the WPF GUI to prompt for the mandatory value, I'm guessing our Host doesn't support that, and it fails. 7.1 doesn't do this because it always uses a text-based prompt rather than trying a GUI prompt.

@JustinGrote
Copy link
Collaborator

@andschwa It is because our PS Host is advertising NonInteractive mode. Read-Host has same problem. Is interactive mode possible with the new pipeline engine?

PSIC> read-host 'test'
read-host : Windows PowerShell is in NonInteractive mode. Read and Prompt 
functionality is not available.
At line:1 char:1
+ read-host 'test'
+ ~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [Read-Host], PSInvalidOperatio 
   nException
    + FullyQualifiedErrorId : InvalidOperation,Microsoft.PowerShell.Commands.ReadH 
   ostCommand

@andyleejordan
Copy link
Member

Oh, good find! I can dig into this.

@andyleejordan
Copy link
Member

So yes, we've been passing -NonInteractive to PowerShell at startup. This sets a flag at a really low level within PowerShell itself, which is a bit frightful, but in my basic testing just now it seems like nothing breaks when we remove the flag. Let's give it a try?

@andyleejordan andyleejordan changed the title Preview v2022.2.0 integrated console: Get-Credential throws exception instead of prompting for input (PS5.1) Get-Credential throws exception instead of prompting for input in Windows PowerShell Feb 22, 2022
@andyleejordan andyleejordan added the Bug: PowerShell 5.1 Bugs when using PowerShell 5.1. label Feb 22, 2022
@andyleejordan andyleejordan changed the title Get-Credential throws exception instead of prompting for input in Windows PowerShell Get-Credential throws exception instead of prompting for input in PowerShell 5.1 Feb 22, 2022
@SydneyhSmith SydneyhSmith moved this from Todo to In Progress in Sea Biscuit Feb 22, 2022
@andyleejordan
Copy link
Member

Ok so apparently we need -NonInteractive to prevent Windows PowerShell from loading its own bundled PSReadLine (this is pending verification, it may no longer be true in PSESv3) and so the previous workaround was that we'd implemented our own Get-Credential hence why this is now showing up. Thanks @SeeminglyScience!

@andyleejordan
Copy link
Member

Looks like we've got a fix!

Repository owner moved this from In Progress to Done in Sea Biscuit Feb 23, 2022
@andyleejordan
Copy link
Member

The fix for this is out in PowerShell Preview v2022.2.2!

@csandfeld
Copy link
Author

That's great news - thanks @andschwa and @JustinGrote

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Extension Terminal Bug: PowerShell 5.1 Bugs when using PowerShell 5.1. Bug: Pre-release Bugs reproducing only in the pre-release extension. Issue-Bug A bug to squash.
Projects
No open projects
Status: Done
Development

Successfully merging a pull request may close this issue.

3 participants