Skip to content

Instantly share code, notes, and snippets.

@manualbashing
Last active November 6, 2019 12:27
Show Gist options
  • Save manualbashing/b409fabb01c784f02614 to your computer and use it in GitHub Desktop.
Save manualbashing/b409fabb01c784f02614 to your computer and use it in GitHub Desktop.
[Get Logged On User] Use WMI to find out, which user is logged in on a specific server.
foreach ($server in $serverNames)
{
Get-WMIObject Win32_Process -Filter 'name="explorer.exe"' -ComputerName $server -PipelineVariable pipedProcess -ErrorAction SilentlyContinue |
Select CSName, @{ Name='User'; Expression={$pipedProcess.GetOwner().User} } |
Write-Output -OutVariable +loggedOnUsers
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment