Skip to content

Get-Process: Add a switch that limits retrieval to the current user's own processes #21301

@mklement0

Description

@mklement0

Summary of the new feature / enhancement

When retrieving processes - either with or without a -Name filter - it would be helpful to allow limiting the set of candidate processes to the current user's own processes, say with a newly introduced -CurrentUser (or -User) switch

# WISHFUL THINKING

# Only retrieve processes started with the current user identity.
Get-Process -CurrentUser

# Only retrieve `cmd` processes started with the current user identity.
Get-Process -CurrentUser -Name cmd

It is often only one's own processes that are of interest, especially when running non-elevated.

In non-elevated sessions, there's currently no easy way to determine which processes are one's own.
Update: One's own means: all processes running with the current user identity, irrespective of how they were started - see discussion in the next two comments.

Even in elevated sessions the solution is cumbersome:
Get-Process -IncludeUserName | Where UserName -eq $env:USERDOMAIN\$env:USERNAME

Proposed technical implementation details (optional)

Add the new switch only to the Name parameter set.

It would be the (possibly -Name-filtered) equivalent of the following, which on Windows can currently only be run with elevation:

#requires -RunAsAdministrator
Get-Process -IncludeUserName  | 
  Where UserName -eq ($IsWindows ? "$env:USERDOMAIN\$env:USERNAME" : $env:USER)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue-Enhancementthe issue is more of a feature request than a bugResolution-DeclinedThe proposed feature is declined.WG-Cmdletsgeneral cmdlet issuesWG-ReviewedA Working Group has reviewed this and made a recommendation

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions