You can get that from WMI by the Win32_LoggedOnUser class, but you have to do some parsing to get it nicely:
gwmi win32_loggedonuser -ComputerName $computername |
foreach {
[PSCustomObject]@{
User = $_.antecedent -replace '.+Domain="(.+)",Name="(.+)"','$1\$2'
Session = $_.dependent -replace '.+LogonID="(\d+)"','$1'
}
}
Or you can use CIM:
Get-CimInstance win32_loggedonuser -ComputerName $computername |
foreach {
[PSCustomObject]@{
User = $_.antecedent -replace '.+Name = "(.+)", Domain = "(.+)".','$2\$1'
Session = $_.dependent -replace '.+LogonID = "(\d+)".','$1'
}
}