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?
Printable View
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?
This script produces the following output: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
}
Quote:
PS C:\foo> .Get-LoggedOnUser.ps1
Logged on user(s):
User: COOKHAM\tfl
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.
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]}
}