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

Assuming you need it in script, PowerShell:

 

(gwmiWin32_LogonSession).GetRelated("Win32_UserAccount")

 

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

  • Anonymous
    January 01, 2003
    The comment has been removed

  • Anonymous
    November 09, 2011
    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'.

  • Anonymous
    November 19, 2012
    The comment has been removed