Last active
November 6, 2019 12:27
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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