Skip to content

Clarify the - limited - usefulness of --%, the stop-parsing token when used with PowerShell commands rather than native programs #10888

@mklement0

Description

@mklement0

Type of issue

Missing information

Feedback

Ultimately, use of --% only makes sense when calling native (external) programs.

  • Direct use of --% with native programs is by far the most common use case.

  • The only scenario in which using --% when calling PowerShell commands makes sense is to relay a raw argument list to a native program, using splatting.

    • In other words: only PowerShell commands that are wrappers for external-programs can meaningfully support --%, where anything following --% is to be passed through to the external program as if --% had been used in direct invocation of said program.

Currently:


Here's an example of a PowerShell function acting as a wrapper for a native program:

function foo {
  $env:SOMEVAR = 1
  # Whatever follows --% in the invocation is captured in a *single* argument, $args[1]
  Write-Verbose -Verbose "`$arg[1]: «$($args[1])»"
  # Note: @args is needed for --% to be relayed properly
  cmd /c echo @args
  $env:SOMEVAR = $null 
}

# Invoke with --%
foo --% a( "x< %SOMEVAR%

Output:

VERBOSE: $arg[1]: «a( "x< %SOMEVAR%»
 a( "x< 1

Note:

Page URL

https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_parsing?view=powershell-7.5#the-stop-parsing-token

Content source URL

https://github.com/MicrosoftDocs/PowerShell-Docs/blob/main/reference/7.5/Microsoft.PowerShell.Core/About/about_Parsing.md

Author

@sdwheeler

Document Id

be402df0-6f04-9a29-5410-c54be1c11926

Metadata

Metadata

Assignees

Labels

area-aboutArea - About_ topics

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions