Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 07-02-2009
Member
 
Join Date: Feb 2008
Posts: 624
Find user logged in with Powershell using WMI

What is the best way of finding out the currently logged in user of a
particular machine?

If I were to write an expression to parse the name out of the value, but I also wanted to know the user who has logged in.

Is there anyone who can help me?
Reply With Quote
  #2  
Old 07-02-2009
Member
 
Join Date: May 2008
Posts: 3,971
Re: Find user logged in with Powershell using WMI

Code:
# Get-LoggedOnUser.ps1
# Get details of the computer

$computers = Get-WmiObject -Class Win32_ComputerSystem 

# Get Logged on User(s)

"Logged on user(s):"

foreach($computer in $computers) {

"User: {0}" -f $computer.UserName

}
This script produces the following output:

Quote:
PS C:\foo> .Get-LoggedOnUser.ps1

Logged on user(s):
User: COOKHAM\tfl
Reply With Quote
  #3  
Old 07-02-2009
Member
 
Join Date: May 2008
Posts: 913
Re: Find user logged in with Powershell using WMI

If both machines are in the same domain/workgroups, then

gwmi win32_process -computer "COMPUTER" -credential "DOMAIN\USER"

assuming domain\user is an administrator on the remote computer, then this should work.
Reply With Quote
  #4  
Old 07-02-2009
Member
 
Join Date: May 2008
Posts: 669
Re: Find user logged in with Powershell using WMI

Provide a computer name and it will return the logged on users.

Code:
function Get-MyLoggedOnUsers
    {
     param([string]$Computer)
     Get-WmiObject Win32_LoggedOnUser -ComputerName $Computer | Select Antecedent -Unique | %{?{0}{1}? -f $_.Antecedent.ToString().Split(???)[1], $_.Antecedent.ToString().Split(???)[3]}
    }
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Find user logged in with Powershell using WMI"
Thread Thread Starter Forum Replies Last Post
How to make Windows 7 show user list on login screen and not just the last logged on user shyman Operating Systems 5 05-08-2010 12:56 PM
Find computer name from which user logged on last time ? OmJaa Active Directory 3 24-09-2009 01:34 AM
Windows could not find your user profile so it logged in to a temporary account.....! TABANL Vista Help 1 27-11-2008 02:29 AM
How do I find out when user XXX logged in+out on last Tuesday? Event log entry possible? hindustnidude Windows XP Support 3 19-03-2008 05:42 AM
DSQUERY to find user not logged in for 120 days Vera Noest Active Directory 2 26-01-2005 06:57 AM


All times are GMT +5.5. The time now is 05:11 AM.