One method of finding the logged on users is to use CIM
$ComputerName = $env:COMPUTERNAME
Get-CimInstance -ClassName Win32_Process -ComputerName $ComputerName -Filter "Name = 'explorer.exe'" | foreach { $lguser = Invoke-CimMethod -InputObject $psitem -MethodName GetOwner $Properties = @{ ComputerName = $ComputerName User = $lguser.User Domain = $lguser.Domain Time = $User.CreationDate } New-Object -TypeName PSObject -Property $Properties }
Get the Win32_Process instances for explorer.exe and foreach of them use the GetOwner method to get the owners names and domain. Create an object and ouput
The post Find the logged on user appeared first on PowerShell for Windows Admins.