Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Using Powershell, I want to do the equivalent of Unix

ps -auxc | grep Emacs

kill -9 364

(Assuming 365 was the pid the first command told me.)

How do I do that? I find it incredibly hard to get Powershell to tell me the owner of a process and the way I tried, getting a wmi-object win32_process and then make that into a list of processes named "explorer.exe" just started lots of explorer.exe instances.

share|improve this question

1 Answer 1

up vote 0 down vote accepted

I found this with a quick google:

$owners = @{}
gwmi win32_process |% {$owners[$_.handle] = $_.getowner().user}

get-process | select processname,Id,@{l="Owner";e={$owners[$_.id.tostring()]}}

seems to return users as requested. You can probably proceed from there. Hope that helps.

share|improve this answer
    
Isn't it amazing how easy and simple Powershell is compared to the old out-dated Unix shells? :-) –  Andrew J. Brehm Feb 10 '11 at 12:04

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.