Find PID with WMI

Hi everybody,

I´ve got a question, I try to find out which PID a User got.

We have several TS and sometimes the Logon process didn´t work, so I have to find out the PID of the User to kill the winlogon.exe (which is executed by SYSTEM).


I allready tried many thinks but nothing succeded ...


Many thanks !

  • What is it you are ultimately trying to accomplish? Just kill their session? And will this be a wholly process or are there automation factors involved?
  • Exactly, there will be a little PS Script where you gonna insert the Username, with this Username i´ll try find out the PID.


    When I have the PID I´m gonna send a taskkill with it so that the user is able to logon again

  • Before we go reinventing the wheel, have you used the Terminal Services module?

  • i've only used this for logging out of RDP sessions, but it may help your situation

    # *** UNTESTED CODE ***
    $username1 = 'george.washington'
    $username2 = ''
    $users = "$username1|$username2"
    $servers = Get-Content 'c:\temp\servers.txt'
    foreach ($server in $servers) {
        # Get all users logged into a server
        $sessions = quser /SERVER:$server
        # Narrow to only sessions where specified users are logged in
        $subset = $sessions | Where-Object {$_ -match $users}
        # Log those users out
        foreach ($entry in $subset) {
            logoff ($entry | % {$_.split() | ? {$_})[1] /SERVER:$server