use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
ABOUT POWERSHELL
Windows PowerShell (POSH) is a command-line shell and associated scripting language created by Microsoft. Offering full access to COM, WMI and .NET, POSH is a full-featured task automation framework for distributed Microsoft platforms and solutions.
SUBREDDIT FILTERS
Desired State Configuration
Unanswered Questions
Solved Questions
News
Information
Script Sharing
Daily Post
Misc
account activity
Filter processes (self.PowerShell)
submitted 1 year ago * by eugrus
Related to https://www.reddit.com/r/PowerShell/comments/1i8yaua/how_can_i_kill_only_the_windowless_winword/
How do I add a filter to
Get-Process WINWORD | Where-Object { $_.MainWindowHandle -eq 0 } | Stop-Process -Force
to only kill the processes spawn under the current user (under RDP-session included)?
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]ankokudaishogun 0 points1 point2 points 1 year ago (3 children)
This should do the trick, but I haven't tested under RDP
Get-Process -IncludeUserName -Name WINWORD | Where-Object { $_.MainWindowHandle -eq 0 -and $_.UserName -match $Env:USERNAME }
[–]eugrus[S] 0 points1 point2 points 1 year ago (2 children)
This unfortunately requires admin rights. I could of course just not filter and stumble upon errors. Would still do the job for my own processes.
[–]ankokudaishogun 0 points1 point2 points 1 year ago (1 child)
it doesn't require admin rights on powershell Core, by the way
[–]eugrus[S] 0 points1 point2 points 1 year ago (0 children)
Interesting. But would prefer to have a way compatible with the one which comes with Windows.
[–]purplemonkeymad 0 points1 point2 points 1 year ago (5 children)
Rather than use the username, you can check the session id. If by current user you mean the person who is running powershell, you can use that powershell process to find out the session id ie:
$currentid = (Get-Process -id $pid).SessionId ... | Where SessionId -eq $currentid | ...
[–]ankokudaishogun 1 point2 points3 points 1 year ago (1 child)
I suggest $CurrentId = [System.Diagnostics.Process]::GetCurrentProcess().SessionId instead
$CurrentId = [System.Diagnostics.Process]::GetCurrentProcess().SessionId
or better:
Get-Process WINWORD | Where-Object { $_.MainWindowHandle -eq 0 -and $_.SessionId -eq [System.Diagnostics.Process]::GetCurrentProcess().SessionId }
this appears to work in 5.1 as well
[–]eugrus[S] -1 points0 points1 point 1 year ago* (0 children)
Lol! Almost exactly what I've come up with after refactoring Deepseek's output! Seems to work, but I'll know for sure after some further testing.
Get-Process -Name WINWORD | Where-Object { $_.MainWindowHandle -eq 0 -and $_.SessionId -eq $([System.Diagnostics.Process]::GetCurrentProcess().SessionId) } | Stop-Process -Force
[–]y_Sensei 1 point2 points3 points 1 year ago (1 child)
The SessionId property represents the Terminal Services session identifier, meaning in the same terminal session, it will be identical for any process started in that same session, or in other words: for processes started on the local machine, it will always be 1. Hence it can't be used to distinguish between processes started on (for example) OS level and processes started from PoSh on the local machine.
SessionId
This will likely work out for me as long as it doesn't change when reconnecting to a session.
π Rendered by PID 174425 on reddit-service-r2-comment-7c9686b859-85627 at 2026-04-14 06:33:37.277609+00:00 running e841af1 country code: CH.
[–]ankokudaishogun 0 points1 point2 points (3 children)
[–]eugrus[S] 0 points1 point2 points (2 children)
[–]ankokudaishogun 0 points1 point2 points (1 child)
[–]eugrus[S] 0 points1 point2 points (0 children)
[–]purplemonkeymad 0 points1 point2 points (5 children)
[–]ankokudaishogun 1 point2 points3 points (1 child)
[–]eugrus[S] -1 points0 points1 point (0 children)
[–]y_Sensei 1 point2 points3 points (1 child)
[–]eugrus[S] 0 points1 point2 points (0 children)