Skip to content

Do not recommend -UseNewEnvironment in connection with -Wait, clarify -UseNewEnvironment behavior #6236

@mklement0

Description

@mklement0

The topic currently states:

When using PowerShell Core on Linux, to open a new process within a new window (similar to the default behavior when using Start-Process in Windows), run the cmdlet with the UseNewEnvironment and Wait parameters. This prevents the new process from blocking PowerShell's control of keyboard input.

The -UseNewEnvironment switch is unrelated to -Wait and should only be used if you do not want to inherit the calling process' environment block. -Wait by itself is enough to prevent the problem of competing for keyboard input.

In fact, -UseNewEnvironment is problematic on Unix and virtually useless in its current form - see PowerShell/PowerShell#4671.


On a related note:

On Windows, when you use UseNewEnvironment, the new process starts only containing the default environment variables defined for the Machine and User scopes. This change was made in PowerShell 7.1.

It's better to call this a bug fix, because that's what it was.
In order words: on Windows, -UseEnvironment didn't work properly up to and including version 7.0 - crucial user-level and dynamic environment variables were missing from the new process' environment, as described in PowerShell/PowerShell#4671

Also:


Document Details

Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

Metadata

Metadata

Assignees

Labels

area-languageArea - PowerShell syntax and keywordsarea-managementArea - Microsoft.PowerShell.Management module

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions