Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > PowerShell

Vista - finding the logged on user (user name) with powershell using WMI?

Reply
 
Old 09-21-2006   #1 (permalink)
klumsy@xtra.co.nz


 
 

finding the logged on user (user name) with powershell using WMI?

whats a good way of finding out the currently logged in user of a
particular machine?

i do

get-WmiObject -computer . Win32_LoggedOnUser

but it returns alot of rows, including network services, users for my
VMWARE, etc etc

plus it seems i'd have to parse the actual user name out of a string
looking like this

Win32_LoggedOnUser.Antecedent="\\\\.\\root\\cimv2:Win32_Account.Domain=\"DCLSW2B1\",Name=\"ANONYMOUS

LOGON\"",Dependent="\\\\.\\root\\cimv2:Win32_LogonSession.LogonId=\"84152\""

or

parse it out of the get properties value

Name : Antecedent
Value :
\\.\root\cimv2:Win32_Account.Domain="DCLSW2B1",Name="NETWORK SERVICE"
Type : Reference
IsLocal : True
IsArray : False
Origin : CIM_Dependency
Qualifiers : {CIMTYPE, key}
Name : Dependent
Value : \\.\root\cimv2:Win32_LogonSession.LogonId="996"
Type : Reference
IsLocal : True
IsArray : False
Origin : CIM_Dependency
Qualifiers : {CIMTYPE, key}


Name : Antecedent
Value :
\\.\root\cimv2:Win32_Account.Domain="DCLSW2B1",Name="__vmware_user__"
Type : Reference
IsLocal : True
IsArray : False
Origin : CIM_Dependency
Qualifiers : {CIMTYPE, key}
Name : Dependent
Value : \\.\root\cimv2:Win32_LogonSession.LogonId="97553"
Type : Reference
IsLocal : True
IsArray : False
Origin : CIM_Dependency
Qualifiers : {CIMTYPE, key}


Name : Antecedent
Value :
\\.\root\cimv2:Win32_Account.Domain="KARLDOMAIN",Name="kprosser"
Type : Reference
IsLocal : True
IsArray : False
Origin : CIM_Dependency
Qualifiers : {CIMTYPE, key}
Name : Dependent
Value : \\.\root\cimv2:Win32_LogonSession.LogonId="133927"
Type : Reference
IsLocal : True
IsArray : False
Origin : CIM_Dependency
Qualifiers : {CIMTYPE, key}



if i have to , its not a biggie to write an expression to parse the
name out of the value, but also i am wanting to user who is logged into
the desktop, and i have no way to distinquish between kprosser and the
others (other than ignoring some common ones)

Help anybody?
Karl


My System SpecsSystem Spec
Old 09-22-2006   #2 (permalink)
Alex B Chalmers


 
 

Re: finding the logged on user (user name) with powershell using WMI?

Karl,

As I understand the login subsystem, and anyone please correct me if I am
wrong, there is no one "logged in" or "desktop" user. Specifically, all
interactive users are provided one or more desktops with which to interact.
Additionally, there is no way to guarantee that any given console session is
actually running through the physically connected input and output devices.
The console session dedicated to the physically attached console, session 0,
is used by RDP connections to Windows XP systems or Windows Server 2003
systems when specifically requested. On server systems, additional console
sessions are allocated when session 0 is not explicitly requested. On a
related note, console sessions that are not actively logged in by a user
also have desktops for the purposes of providing login mechanisms.

Is there something more specific that you are trying to achieve?

- Alex B Chalmers


<klumsy@xtra.co.nz> wrote in message
news:1158880817.192591.42750@i3g2000cwc.googlegroups.com...
> whats a good way of finding out the currently logged in user of a
> particular machine?
>
> i do
>
> get-WmiObject -computer . Win32_LoggedOnUser
>
> but it returns alot of rows, including network services, users for my
> VMWARE, etc etc
>
> plus it seems i'd have to parse the actual user name out of a string
> looking like this
>
> Win32_LoggedOnUser.Antecedent="\\\\.\\root\\cimv2:Win32_Account.Domain=\"DCLSW2B1\",Name=\"ANONYMOUS
>
> LOGON\"",Dependent="\\\\.\\root\\cimv2:Win32_LogonSession.LogonId=\"84152\""
>
> or
>
> parse it out of the get properties value
>
> Name : Antecedent
> Value :
> \\.\root\cimv2:Win32_Account.Domain="DCLSW2B1",Name="NETWORK SERVICE"
> Type : Reference
> IsLocal : True
> IsArray : False
> Origin : CIM_Dependency
> Qualifiers : {CIMTYPE, key}
> Name : Dependent
> Value : \\.\root\cimv2:Win32_LogonSession.LogonId="996"
> Type : Reference
> IsLocal : True
> IsArray : False
> Origin : CIM_Dependency
> Qualifiers : {CIMTYPE, key}
>
>
> Name : Antecedent
> Value :
> \\.\root\cimv2:Win32_Account.Domain="DCLSW2B1",Name="__vmware_user__"
> Type : Reference
> IsLocal : True
> IsArray : False
> Origin : CIM_Dependency
> Qualifiers : {CIMTYPE, key}
> Name : Dependent
> Value : \\.\root\cimv2:Win32_LogonSession.LogonId="97553"
> Type : Reference
> IsLocal : True
> IsArray : False
> Origin : CIM_Dependency
> Qualifiers : {CIMTYPE, key}
>
>
> Name : Antecedent
> Value :
> \\.\root\cimv2:Win32_Account.Domain="KARLDOMAIN",Name="kprosser"
> Type : Reference
> IsLocal : True
> IsArray : False
> Origin : CIM_Dependency
> Qualifiers : {CIMTYPE, key}
> Name : Dependent
> Value : \\.\root\cimv2:Win32_LogonSession.LogonId="133927"
> Type : Reference
> IsLocal : True
> IsArray : False
> Origin : CIM_Dependency
> Qualifiers : {CIMTYPE, key}
>
>
>
> if i have to , its not a biggie to write an expression to parse the
> name out of the value, but also i am wanting to user who is logged into
> the desktop, and i have no way to distinquish between kprosser and the
> others (other than ignoring some common ones)
>
> Help anybody?
> Karl
>


My System SpecsSystem Spec
Old 09-22-2006   #3 (permalink)
=?Utf-8?B?SmFrZURBSFM=?=


 
 

RE: finding the logged on user (user name) with powershell using WMI?

(gwmi -class win32_computerSystem).username

will show the user currently logged onto the machine. Doesnt retrun results
as far as I know for "guest" users on the machine.

-Jake


"klumsy@xtra.co.nz" wrote:

> whats a good way of finding out the currently logged in user of a
> particular machine?
>
> i do
>
> get-WmiObject -computer . Win32_LoggedOnUser
>
> but it returns alot of rows, including network services, users for my
> VMWARE, etc etc
>
> plus it seems i'd have to parse the actual user name out of a string
> looking like this
>
> Win32_LoggedOnUser.Antecedent="\\\\.\\root\\cimv2:Win32_Account.Domain=\"DCLSW2B1\",Name=\"ANONYMOUS
>
> LOGON\"",Dependent="\\\\.\\root\\cimv2:Win32_LogonSession.LogonId=\"84152\""
>
> or
>
> parse it out of the get properties value
>
> Name : Antecedent
> Value :
> \\.\root\cimv2:Win32_Account.Domain="DCLSW2B1",Name="NETWORK SERVICE"
> Type : Reference
> IsLocal : True
> IsArray : False
> Origin : CIM_Dependency
> Qualifiers : {CIMTYPE, key}
> Name : Dependent
> Value : \\.\root\cimv2:Win32_LogonSession.LogonId="996"
> Type : Reference
> IsLocal : True
> IsArray : False
> Origin : CIM_Dependency
> Qualifiers : {CIMTYPE, key}
>
>
> Name : Antecedent
> Value :
> \\.\root\cimv2:Win32_Account.Domain="DCLSW2B1",Name="__vmware_user__"
> Type : Reference
> IsLocal : True
> IsArray : False
> Origin : CIM_Dependency
> Qualifiers : {CIMTYPE, key}
> Name : Dependent
> Value : \\.\root\cimv2:Win32_LogonSession.LogonId="97553"
> Type : Reference
> IsLocal : True
> IsArray : False
> Origin : CIM_Dependency
> Qualifiers : {CIMTYPE, key}
>
>
> Name : Antecedent
> Value :
> \\.\root\cimv2:Win32_Account.Domain="KARLDOMAIN",Name="kprosser"
> Type : Reference
> IsLocal : True
> IsArray : False
> Origin : CIM_Dependency
> Qualifiers : {CIMTYPE, key}
> Name : Dependent
> Value : \\.\root\cimv2:Win32_LogonSession.LogonId="133927"
> Type : Reference
> IsLocal : True
> IsArray : False
> Origin : CIM_Dependency
> Qualifiers : {CIMTYPE, key}
>
>
>
> if i have to , its not a biggie to write an expression to parse the
> name out of the value, but also i am wanting to user who is logged into
> the desktop, and i have no way to distinquish between kprosser and the
> others (other than ignoring some common ones)
>
> Help anybody?
> Karl
>
>

My System SpecsSystem Spec
Old 09-25-2006   #4 (permalink)
Jacques Barathon [MS]


 
 

Re: finding the logged on user (user name) with powershell using WMI?

Alex is right. That said, your PowerShell session runs under a particular
security context, so if what you are trying to achieve is to get the
corresponding account you can use this:

[System.Security.Principal.WindowsIdentity]::GetCurrent()

Jacques

"Alex B Chalmers" <alex@alexbchalmers.com> a écrit dans le message de news:
1AF402DD-CEBD-4DA6-8946-FF4B56484EC6@microsoft.com...
> Karl,
>
> As I understand the login subsystem, and anyone please correct me if I am
> wrong, there is no one "logged in" or "desktop" user. Specifically, all
> interactive users are provided one or more desktops with which to
> interact. Additionally, there is no way to guarantee that any given
> console session is actually running through the physically connected input
> and output devices. The console session dedicated to the physically
> attached console, session 0, is used by RDP connections to Windows XP
> systems or Windows Server 2003 systems when specifically requested. On
> server systems, additional console sessions are allocated when session 0
> is not explicitly requested. On a related note, console sessions that are
> not actively logged in by a user also have desktops for the purposes of
> providing login mechanisms.
>
> Is there something more specific that you are trying to achieve?
>
> - Alex B Chalmers
>
>
> <klumsy@xtra.co.nz> wrote in message
> news:1158880817.192591.42750@i3g2000cwc.googlegroups.com...
>> whats a good way of finding out the currently logged in user of a
>> particular machine?
>>
>> i do
>>
>> get-WmiObject -computer . Win32_LoggedOnUser
>>
>> but it returns alot of rows, including network services, users for my
>> VMWARE, etc etc
>>
>> plus it seems i'd have to parse the actual user name out of a string
>> looking like this
>>
>> Win32_LoggedOnUser.Antecedent="\\\\.\\root\\cimv2:Win32_Account.Domain=\"DCLSW2B1\",Name=\"ANONYMOUS
>>
>> LOGON\"",Dependent="\\\\.\\root\\cimv2:Win32_LogonSession.LogonId=\"84152\""
>>
>> or
>>
>> parse it out of the get properties value
>>
>> Name : Antecedent
>> Value :
>> \\.\root\cimv2:Win32_Account.Domain="DCLSW2B1",Name="NETWORK SERVICE"
>> Type : Reference
>> IsLocal : True
>> IsArray : False
>> Origin : CIM_Dependency
>> Qualifiers : {CIMTYPE, key}
>> Name : Dependent
>> Value : \\.\root\cimv2:Win32_LogonSession.LogonId="996"
>> Type : Reference
>> IsLocal : True
>> IsArray : False
>> Origin : CIM_Dependency
>> Qualifiers : {CIMTYPE, key}
>>
>>
>> Name : Antecedent
>> Value :
>> \\.\root\cimv2:Win32_Account.Domain="DCLSW2B1",Name="__vmware_user__"
>> Type : Reference
>> IsLocal : True
>> IsArray : False
>> Origin : CIM_Dependency
>> Qualifiers : {CIMTYPE, key}
>> Name : Dependent
>> Value : \\.\root\cimv2:Win32_LogonSession.LogonId="97553"
>> Type : Reference
>> IsLocal : True
>> IsArray : False
>> Origin : CIM_Dependency
>> Qualifiers : {CIMTYPE, key}
>>
>>
>> Name : Antecedent
>> Value :
>> \\.\root\cimv2:Win32_Account.Domain="KARLDOMAIN",Name="kprosser"
>> Type : Reference
>> IsLocal : True
>> IsArray : False
>> Origin : CIM_Dependency
>> Qualifiers : {CIMTYPE, key}
>> Name : Dependent
>> Value : \\.\root\cimv2:Win32_LogonSession.LogonId="133927"
>> Type : Reference
>> IsLocal : True
>> IsArray : False
>> Origin : CIM_Dependency
>> Qualifiers : {CIMTYPE, key}
>>
>>
>>
>> if i have to , its not a biggie to write an expression to parse the
>> name out of the value, but also i am wanting to user who is logged into
>> the desktop, and i have no way to distinquish between kprosser and the
>> others (other than ignoring some common ones)
>>
>> Help anybody?
>> Karl
>>

>


My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Script to find all user and what PC they are logged into VB Script
Re: Cannot use ie7 when logged on as a standard user?? Vista security
how to get logged-in user credentials? PowerShell
User Profile Bad if this user is not first user logged onto Vista Vista account administration
Remember last user logged on Vista account administration


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46