Forum Discussion

mkamsad's avatar
mkamsad
Copper Contributor
Sep 20, 2021
Solved

Get-ADUser from Get-AdGroupMember? Trying to get list of users using list of computers

Hi, I am trying to retrieve a list of users that have or are logged on to certain computers. The computers are all part of a security group and I have retrieved and saved the list using:   Get-ADG...
  • psophos's avatar
    Sep 20, 2021

    mkamsadsummat like:

    $ProcessList = gwmi win32_process -computer $Computer.Name -Filter "Name = 'explorer.exe'"
    Write-Verbose "$($ProcessList.Count) explorer.exe processes running"
    
    foreach ($Process in $ProcessList)
    {
        # Search collection of processes for username
        $processOwner = ($Process.GetOwner()).User
    
        # ... owner of the explorer.exe process is someone who is logged on to thsi computer
    }

     

    You'd have to execute the above code for each computer, return a list of logged on users filtering out a few generic accounts that you don't want to report on.

     

Resources