PowerShell / PowerShell/PowerShell

Allow `$PSCmdlet` methods in constrained language

Open
#17,906 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Issue-Enhancement Needs-Triage WG-Cmdlets WG-Reviewed WG-Security
Dominant language
C#
Stars
55.5k
Forks
8.5k
Avg merge
1d 2h
Merged PRs (30d)
88

Description

Summary of the new feature / enhancement

The following fails when using constrained language mode:

function Test-ShouldProcess {
     [CmdletBinding(SupportsShouldProcess, ConfirmImpact = 'High')]
     param()

     if($PSCmdlet.ShouldProcess('something')) {
         return $true
     }
}

Error:

Cannot invoke method. Method invocation is supported only on core types in this language mode.

Other usages are also blocked, such as getting preference variables from caller scope within modules:

  param (
    $VerbosePreference = $PSCmdlet.GetVariableValue('VerbosePreference')
  )
Proposed technical implementation details (optional)

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the ShouldProcess and GetVariableValue examples in constrained language mode, then trace the constrained-language method invocation handling. Define the permitted $PSCmdlet methods and verify that those calls work without weakening restrictions on other method invocations.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp, powershell
Domain
cli, security
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.