Skip to content

Pass parameters to PowerShell.exe (specifically NonInteractive) #1470

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

Open
ohadschn opened this issue Aug 7, 2018 · 5 comments
Open

Pass parameters to PowerShell.exe (specifically NonInteractive) #1470

ohadschn opened this issue Aug 7, 2018 · 5 comments
Labels
Area-Extension Terminal Issue-Enhancement A feature request (enhancement). Up for Grabs Will shepherd PRs.

Comments

@ohadschn
Copy link

ohadschn commented Aug 7, 2018

PowerShell.exe supports various command-line flags. It would be beneficial to allow control over these arguments. Specifically, I want to run powershell.exe -NonInteractive. This is especially useful when powershell.debugging.createTemporaryIntegratedConsole is set to true so you get an isolated run with the exact environment you want.

I tried using the args setting in launch.json but that seems to pass parameters directly to my script, after powershell.exe has already been loaded (with parameters I have no control over).

@SeeminglyScience
Copy link
Collaborator

Technically we already do pass -NonInteractive, but only because we use a custom PSHost.

We should definitely look into implementing a host that mirrors the default -NonInteractive experience though.

@gmckeown
Copy link

Related to the comment from @SeeminglyScience, I've got a bunch of PowerShell scripts that are typically executed by an automation platform with "-noninteractive". These scripts rely on some files containing secure-string credentials when running automatically, but I've just been investigating ways to allow them to prompt for credentials when run interactively from the command-line.

Rightly or wrongly, I'm checking for the presence of "-noninteractive" on the command-line, and this works well from a standalone PowerShell instance. Inside VSCode, however, the script thinks its being run on the automation platform and so doesn't prompt for creds.

I'll find a work-around for now, but "a host that mirrors the default -NonInteractive experience" sounds helpful to me!

@ghost ghost added the Needs: Maintainer Attention Maintainer attention needed! label Jul 15, 2020
@rjmholt
Copy link
Contributor

rjmholt commented Jul 15, 2020

Rather than check the command line parameters, I would check $Host.Name and in the case of ConsoleHost this property and this property might be indicative.

Generally though, I'm not sure how we would best emulate non-interactive startup, because it's a startup option -- there's no big switch inside the runtime to turn it on and off. I suspect that perfecting attach-to-process debugging is going to be the best option here

@SeeminglyScience
Copy link
Collaborator

SeeminglyScience commented Jul 15, 2020

Rather than check the command line parameters, I would check $Host.Name and in the case of ConsoleHost this property and this property might be indicative.

I've often wished there was a public property for this :/

Even if you're willing to use reflection, this is a bigger pain than usual to get to because it's not on InternalHost. So you gotta go through Host.ExternalHost.UI.NoPrompt. It'll also fall apart when in remoting scenarios, though I suppose you can guess that if the host actually changed then it's interactive. Edit: I guess you can't can you? Host probably still changes even in Invoke-Command?

Generally though, I'm not sure how we would best emulate non-interactive startup, because it's a startup option -- there's no big switch inside the runtime to turn it on and off. I suspect that perfecting attach-to-process debugging is going to be the best option here

The cheapest way imo would be to add a property to Host.PrivateData and check it on host UI calls like ConsoleHost does with NoPrompt.

I'd be interested to hear some specifics about use cases though. I'm not sure I understand the value.

Note that what I'm proposing wouldn't really emulate it in a way that would solve your problem @gmckeown. I think it's safe to say that there is currently no reliable or supported way of "detecting" non-interactive and best practices would recommend against attempting to account for it.

@gmckeown
Copy link

@rjmholt @SeeminglyScience Thanks for the insight!

@SydneyhSmith SydneyhSmith removed the Needs: Maintainer Attention Maintainer attention needed! label Jul 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Extension Terminal Issue-Enhancement A feature request (enhancement). Up for Grabs Will shepherd PRs.
Projects
None yet
Development

No branches or pull requests

6 participants