none
Retrieve Running Process User Name in Powershell RRS feed

  • Question

  • Hello Everyone!

    I'm trying to find a powershell command that will retrieve the user name of a process.  Specifically I want to set to a variable the user name associated with explorer.exe.  Can this be done?

    Thank you in advance!!


    Monday, February 24, 2014 7:48 PM

Answers

  • Start with this:

     gwmi win32_process -filter 'name="explorer.exe"'|%{$_.GetOwner()}|select domain,user


    ¯\_(ツ)_/¯

    • Marked as answer by NeedAnswers8 Monday, February 24, 2014 8:17 PM
    Monday, February 24, 2014 8:12 PM

All replies

  • Yep; just use Get-Process with the -IncludeUserName switch:

    $processes = Get-Process -Name explorer.exe -IncludeUserName
    
    $processes

    Depending on how many instances of explorer.exe are running on the machine, $processes may be an array, so you'd have to decide how to proceed from there.

    Monday, February 24, 2014 8:11 PM
  • Start with this:

     gwmi win32_process -filter 'name="explorer.exe"'|%{$_.GetOwner()}|select domain,user


    ¯\_(ツ)_/¯

    • Marked as answer by NeedAnswers8 Monday, February 24, 2014 8:17 PM
    Monday, February 24, 2014 8:12 PM
  • Thanks for your reply David! However that command yields an error for me (as shown below).  I'm using version 3.0... would that be the problem?
    Monday, February 24, 2014 8:16 PM
  • Try

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

    • Proposed as answer by Peter Ziganki Monday, February 24, 2014 8:20 PM
    Monday, February 24, 2014 8:16 PM
  • Thanks JRV!!  That did the trick!

    I set that to a variable followed by $variableName.User

    Monday, February 24, 2014 8:19 PM
  • Thanks for your reply David! However that command yields an error for me (as shown below).  I'm using version 3.0... would that be the problem?

    To use the command like that you need to run elevated.  The other method will not return all names but will not throw an exception.


    ¯\_(ツ)_/¯

    Monday, February 24, 2014 9:04 PM