Skip to content

Add -Current Parameter to Get-Process#27037

Open
kilasuit wants to merge 5 commits into
PowerShell:masterfrom
kilasuit:GetCurrentProcess
Open

Add -Current Parameter to Get-Process#27037
kilasuit wants to merge 5 commits into
PowerShell:masterfrom
kilasuit:GetCurrentProcess

Conversation

@kilasuit

@kilasuit kilasuit commented Mar 15, 2026

Copy link
Copy Markdown
Collaborator

PR Summary

Return Current Process via Get-Process -Current to support Restricted Language Mode
Fixes #27028

PR Context

PR Checklist

Copilot AI review requested due to automatic review settings March 15, 2026 22:49

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new -Current switch to Get-Process to return the current PowerShell process without requiring $PID, intended to work in RestrictedLanguage scenarios (per #27028).

Changes:

  • Introduces a new MatchMode.ByCurrent and routes selection to Process.GetCurrentProcess().
  • Adds -Current (and CurrentWithUserName parameter set support) to Get-Process.
  • Adds a Pester test validating Get-Process -Current returns a single process with the current PID.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.

File Description
src/Microsoft.PowerShell.Commands.Management/commands/management/Process.cs Adds the new selection mode and -Current parameter set wiring for Get-Process.
test/powershell/Modules/Microsoft.PowerShell.Management/Get-Process.Tests.ps1 Adds a new test asserting basic -Current behavior.

You can also share your feedback on Copilot code review. Take the survey.

Comment thread src/Microsoft.PowerShell.Commands.Management/commands/management/Process.cs Outdated
Comment thread src/Microsoft.PowerShell.Commands.Management/commands/management/Process.cs Outdated
Comment thread src/Microsoft.PowerShell.Commands.Management/commands/management/Process.cs Outdated
@kilasuit

Copy link
Copy Markdown
Collaborator Author

I will take another stab at what has been raised shortly

@kilasuit kilasuit marked this pull request as draft March 15, 2026 23:47
@kilasuit kilasuit force-pushed the GetCurrentProcess branch from 597fa61 to 8d175dd Compare March 16, 2026 22:51
@kilasuit kilasuit marked this pull request as ready for review March 16, 2026 22:51
@kilasuit kilasuit requested a review from a team as a code owner March 16, 2026 22:51
@kilasuit kilasuit added the CL-General Indicates that a PR should be marked as a general cmdlet change in the Change Log label Mar 16, 2026
@kilasuit kilasuit added the WG-Cmdlets general cmdlet issues label Mar 16, 2026
@doctordns

Copy link
Copy Markdown
Collaborator

As mentioned in #27037, the name of the parameter -Current is not obvious and not very discoverable. I'd like the name to be more obvious, such as -CurrentPowerShellProcess. If we have to, we could then use ``-current` as an alternative name for this parameter.

@kilasuit

kilasuit commented Mar 18, 2026

Copy link
Copy Markdown
Collaborator Author

@doctordns - the parameter Current is for most people going to be self explanitory as you are clearly looking to get the Current Process surfacing & using the PowerShell Engine.

There isn't any real need to expand this to CurrentPowerShellProcess and also as PowerShell can be embedded in a C# application calling this would then return that applications process as there is no real PowerShell process to return.

So it doesn't actually make sense to call it as such.

@microsoft-github-policy-service microsoft-github-policy-service Bot added the Review - Needed The PR is being reviewed label Mar 26, 2026
@SteveL-MSFT SteveL-MSFT added the WG-NeedsReview Needs a review by the labeled Working Group label Apr 1, 2026
@SteveL-MSFT SteveL-MSFT moved this from Queue to In-Progress-PullRequests in Cmdlets Working Group Apr 1, 2026
@SteveL-MSFT SteveL-MSFT added the WG-Security security related areas such as JEA label Apr 1, 2026
@SteveL-MSFT

Copy link
Copy Markdown
Member

The @PowerShell/wg-powershell-cmdlets discussed this. Since $PID is explicitly not allowed in RestrictedLanguage mode. We are concerned if this would be a workaround to a deliberately intended design. We ask the Security WG to review. Otherwise, we don't have concerns about Get-Process -Current

@SteveL-MSFT SteveL-MSFT removed the WG-Cmdlets general cmdlet issues label Apr 1, 2026
@microsoft-github-policy-service microsoft-github-policy-service Bot removed the Review - Needed The PR is being reviewed label Apr 1, 2026
@microsoft-github-policy-service microsoft-github-policy-service Bot added the Review - Needed The PR is being reviewed label Apr 8, 2026
@kilasuit

kilasuit commented Jun 15, 2026

Copy link
Copy Markdown
Collaborator Author

On further review prior to Engine WG discussing #26950 & also based on @SteveL-MSFT comment above I think that to please the Security WG would be best for if Get-Process -Current is run in a RestrictedLanguage mode that this should return an Unsupported in this Language Mode error to the caller.

As such there will be more work to do in this PR to achieve this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CL-General Indicates that a PR should be marked as a general cmdlet change in the Change Log Review - Needed The PR is being reviewed WG-NeedsReview Needs a review by the labeled Working Group WG-Security security related areas such as JEA

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add -Current Parameter to Get-Process

4 participants