Skip to content

Start-Process on Windows: -Environment is quietly ignored when -Verb RunAs is also specified, combination should be prevented. #20923

@mklement0

Description

@mklement0

Prerequisites

Steps to reproduce

Note:

  • I'm assuming that the underlying .NET / Windows APIs don't support this combination; if so, an error should be reported.

  • Indeed the .NET APIs actively prevent the analogous combination (not sure about direct use of the WinAPI): .Verb = "RunAs" requires .UseShellExecute = true, which in turn actively prevents modifying the environment via .Environment or .EnvironmentVariables (exception "The Process object must have the UseShellExecute property set to false in order to use environment variables.").

Start-Process -Verb RunAs cmd -Environment @{ foo='new' } '/c "echo [%foo%]" & pause' -Wait

Expected behavior

An error indicating that the specific parameter combination isn't supported.

Actual behavior

The process is launched, and the -Environment argument is quietly ignored.

[%foo%]

Error details

No response

Environment data

PowerShell 7.4.0 on W11 22H2

Visuals

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue-BugIssue has been identified as a bug in the productResolution-No ActivityIssue has had no activity for 6 months or moreUp-for-GrabsUp-for-grabs issues are not high priorities, and may be opportunities for external contributors

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions