How to determine if current user is a domain or local user?

Assuming you need it in script, PowerShell:




If you expect more than one logon session, then


(gwmi Win32_Process -filter “Handle = $Pid”).GetRelated(“Win32_LogonSession”) |% {$_.GetRelated(“Win32_UserAccount”)}


will give you Win32_UserAccount for the account used to run current powershell instance.

Comments (3)

  1. danma_ says:

    Hi Srikanth,

    it's powershell script, the script works perfect:

    1. click start -> type "powershell" in search box

    2. copy and paste the script in the powershell window and press enter.

  2. srikanth says:

    When i try (gwmi Win32_LogonSession).GetRelated("Win32_UserAccount"), I get an error

    Method invocation failed because [System.Object[]] doesn't contain a method named 'GetRelated'.

  3. howard tingley says:

    microsoft has a page for me and i can not get passed it to get to my inbox or junk mail please help me to get this problem solved. my phone is217-826-2128