Get Logged On User – From 4sysops.com Adam Bertram
Found this at 4sysops.com, and have been using it for a while, take a look at Adam’s post for the full run down.
function Get–LoggedOnUser
{
[CmdletBinding()]
param
(
[Parameter()]
[ValidateScript({ Test–Connection –ComputerName $_ –Quiet –Count 1 })]
[ValidateNotNullOrEmpty()]
[string[]]$ComputerName = $env:COMPUTERNAME
)
foreach ($comp in $ComputerName)
{
$output = @{ ‘ComputerName’ = $comp }
$output.UserName = (Get–WmiObject –Class win32_computersystem –ComputerName $comp).UserName
[PSCustomObject]$output
}
}