Skip to content

Add -Current Parameter to Get-Process#27037

Open
kilasuit wants to merge 5 commits intoPowerShell:masterfrom
kilasuit:GetCurrentProcess
Open

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

Conversation

@kilasuit
Copy link
Collaborator

@kilasuit kilasuit commented Mar 15, 2026

PR Summary

Return Current Process via Get-Command -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
Copy link
Contributor

Copilot AI left a comment

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.

@kilasuit
Copy link
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
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
Copy link
Collaborator Author

kilasuit commented Mar 18, 2026

@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
@microsoft-github-policy-service
Copy link
Contributor

This pull request has been automatically marked as Review Needed because it has been there has not been any activity for 7 days.
Maintainer, please provide feedback and/or mark it as Waiting on Author

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-Cmdlets general cmdlet issues

Projects

Status: Queue

Development

Successfully merging this pull request may close these issues.

Add -Current Parameter to Get-Process

3 participants