What you are doing is not correct to give you what you are after. Please be sure to read the help file entirely, especially the parameters and examples.
Not all properties are available by default. So, you must specifically ask for them, and even with that, some things change over time. What you are doing no longer returns anything in the user name.
You need to use the built-in Windows ‘Qwinsta’
or, there’s the built-in Windows command, “query”, located at %SystemRoot%\system32\query.exe
query user /server:SomeComputerName
or install and use this module…
Or use a different .Net class.
All users that have ever logged on a target system
Get-WmiObject -Class Win32_LoggedonUser -ComputerName $env:COMPUTERNAME |
Select-Object -Property Antecedent
Or try pre-built stuff
Find the logged on users on a remote system/s
DescriptionThis script should be useful for Helpdesk or other IT Admins to query remote machines to see who is logged on.This could also be useful for Remote Desktop Services or Citrix Admins * Note this scripts also returns non system accounts that are running services.
tagging in on Joel’s pointer… just a heads up…
Agreed, Write-Host, outside of specific needs should not be used, …
Sending things to the screen in general does not require Write anything. It’s a default action.
but… as to the normal pointer go to in order back up such statements.
… Jeffrey Snover change his stance on this as of May 2016.
With PowerShell v5 Write-Host no longer “kills puppies”. data is captured into info stream …