i'm surprised nobody mentioned tasklist
it seems almost tailor made to do this since you can just apply a filter to only pull processes by username:tasklist.exe /fi "USERNAME eq $env:USERNAME"
will spit out all processes by the current user. no fuss, no admin, no wmi
it spits out an array of text so it's very easy to access and manipulate
want the nth task? just slap the index next to the command(tasklist.exe /fi "USERNAME eq $env:USERNAME")[i]
looking for a particular process? pipe it into findstrtasklist.exe /fi "USERNAME eq $env:USERNAME" | findstr.exe /i /r /c:"task*"
here's my oneliner to pull the pid of a desired task from the current user*((tasklist.exe /fi "USERNAME eq $env:USERNAME" /FO CSV | findstr.exe /i /r /c:"task*") -replace('"\S+",("\d{2,}").*', '$1')) -replace ('"(\d+).*', '$1')
which of course you can then pass to eitherStop-Process -Id $(((tasklist.exe /fi "USERNAME eq $env:USERNAME" /FO CSV | findstr.exe /i /r /c:"task*") -replace('"\S+",("\d{2,}").*', '$1')) -replace ('"(\d+).*', '$1'))
or a more graceful taskkilltaskkill.exe /PID $(((tasklist.exe /fi "USERNAME eq $env:USERNAME" /FO CSV | findstr.exe /i /r /c:"task*") -replace('"\S+",("\d{2,}").*', '$1')) -replace ('"(\d+).*', '$1'))
*explanation
get the all of the current user's taskstasklist.exe /fi "USERNAME eq $env:USERNAME"
format the output as comma separated (gives us anchors when manipulating the output with regex)/FO CSV
find your desired task findstr.exe /i /r /c:"task*"/i case-insensitive/r regex/c: literal string
this first replace will spit out the PID with quotations thanks to the CSV formatreplace('"\S+",("\d{2,}").*', '$1')
so you'd get something like "1234" hence, the second replace to clean the quotation marksreplace ('"(\d+).*', '$1')
if you want all the PIDs of the current user for some reason, here you go((tasklist.exe /fi "USERNAME eq $env:USERNAME" /FO CSV) -replace('"\S+",("\d{2,}").*', '$1')) -replace ('"(\d+).*', '$1')
anyway, cheers hope this helps someone in the future!!