Show Logged On User Tool.txt - Notepad

Show Logged On User Tool

The below PowerShell script should be run as an administrator. You can use it to determine who is currently logged onto a remote computer. The script will ask the user for a computername and the run a WMI query against the name.
#Formatting
mode con: lines=20
$a = (Get-Host).UI.RawUI
$a.WindowTitle = "Show Logged On User Tool"
$a.BackgroundColor = "darkcyan"
$a.ForegroundColor = "white"
(get-host).privatedata.errorforegroundcolor="yellow"
(get-host).privatedata.errorbackgroundcolor="darkcyan"
do
{
Clear-Host
$nl = [Environment]::NewLine

#Input
Write-Host "Welcome to the Show Logged On User Tool - Author Nick Beare"
$nl
$target2 = read-host "Please enter the computer name of the machine you would like to report on"
$target = $target2.ToUpper()
$nl
Write-Host "The below user is currently logged onto $target."

#Processing and Output
get-wmiobject -computername $target -class win32_computersystem | select-object username
$nl
write-host "If the above result has a blank username then nobody is currently logged onto $target. If an RPC error is encountered then $target is unreachable."
$nl
$response = read-host "Enter 'Y' and hit enter to check another machine. To quit, enter any other key and hit enter"
}
while ($response -eq "Y")


Back