Sep 20 2021 09:14 AM - edited Sep 20 2021 10:23 AM
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-ADGroupMember security-group-name | Export-CSV complist.csv
From this list, I'd like to find out who the users are of each of these computers.
If there is a better way to achieve what's being asked, please feel free to share.
Thank you!
Sep 20 2021 10:33 AM
Solution@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.
Sep 20 2021 11:08 AM
@psophos @psophos Thank you for that answer. It helped me to rethink about my question. I guess, my question can be reframed as: "Does AD store name of a user logged on to a particular computer?" If the answer is yes, can it be retrieved using powershell? If the answer is no, then what other tool can be used to retrieve that information using a script?
Sep 20 2021 11:42 AM
Sep 22 2021 04:07 PM