Results 1 to 4 of 4

Thread: Find user logged in with Powershell using WMI

  1. #1
    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?

  2. #2
    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:

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

    Logged on user(s):
    User: COOKHAM\tfl

  3. #3
    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.

  4. #4
    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]}
        }

Similar Threads

  1. Replies: 6
    Last Post: 29-03-2015, 08:39 PM
  2. Replies: 3
    Last Post: 24-09-2009, 01:34 AM
  3. Replies: 1
    Last Post: 27-11-2008, 02:29 AM
  4. Replies: 3
    Last Post: 19-03-2008, 05:42 AM
  5. DSQUERY to find user not logged in for 120 days
    By Vera Noest in forum Active Directory
    Replies: 2
    Last Post: 26-01-2005, 06:57 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,714,033,572.27210 seconds with 16 queries