Return Logged on User in PowerShell

email me

# Get details of this computer
$computers = Get-WmiObject -Class Win32_ComputerSystem

# Get Logged on User
"Logged on user(s):"
foreach($computer in $computers) {
# Show Logged on User
"User: {0}" -f $computer.UserName
}
# Timing to view user name
Start-Sleep -s 5