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… Read the full text.