Kill process of a different user remotely

This topic contains 3 replies, has 2 voices, and was last updated by  kate Ritter 1 year, 9 months ago.

  • Author
  • #51869

    kate Ritter

    Hi there,

    I'm just learning the basics of powershell and I wanted to resolve the following issue:

    I need to kill a specific task that is run on a remote computer by all users that are not currently logged in.

    I want to be able to run the command on a Windows 7 machine.

    What I got so far:

    Get-WmiObject win32_process -computername AAA | select name,@{n="owner";e={$_.getowner().user}} | where{$ -like "*lync*"} | where{$_.owner -ne "BBB"}

    this gives me all processes with *lync* on the computer AAA that are not from User BBB. So far so good. but how would I end these processes now?
    I tried with foreach {$_.terminate()} but that did not work.

    It would be nice if someone could help me with the last step.

    Thank you

    Best regards,

  • #51878

    Dan Potter

    Use invoke-command with stop-process, it'll be easier for you.

    The wmi method would be terminate. Really important to understand methods and properties of objects when learning powershell. Do not turn objects into custom objects with the select statement(you will lose the methods if you do). Don't use |where |where, use -and.

    Get-WmiObject win32_process -computername AAA | select -first 1 |gm

  • #51880

    Dan Potter

    btw, if you google 'get-wmiobject stop process' you'll have tons of resources that explain how to do this.

  • #52032

    kate Ritter

    Hello Dan,

    thank you for your response.

    Thanks to your input I got it – I still had to play around a little but this seems to work now:

    Get-WmiObject win32_process -computername AAA -filter "name='lync.exe'" | Where-Object {$_.getowner().user -ne "BBB"} | Invoke-WmiMethod -name terminate

    Thank you so much for your help 🙂

    Best regards,

You must be logged in to reply to this topic.