Win32_ComputerSystem and UserName

I have this code:

$machine = 'AnyPC'
$computerSystem = Get-WMIObject -class Win32_ComputerSystem -ComputerName $machine
$computerName = $computerSystem.name
$model = $computerSystem.model
$LoggedUser = $computerSystem.UserName
$LoggedUser

Now, this code seems to work fine, I can change AnyPC to many different machines where I know who is logged on and it returns the correct user.  But I've now come across 2 machines where it returns a users name who does Not even have a profile on the machine.   How accurate is this key?  I have a larger script that depends on this data being 100% accurate and it does not appear to be.   

 

Parents
No Data
Reply
  • The problem is that more that one user can be logged onto a system. The MSDN documentation tells you what to expect.

    msdn.microsoft.com/.../aa394102(v=vs.85).aspx

    UserName
    Data type: string
    Access type: Read-only
    Qualifiers: MappingStrings ("Win32API|System Information Functions|GetUserName")

    Name of a user that is logged on currently. This property must have a value. In a terminal services session, UserName returns the name of the user that is logged on to the console—not the user logged on during the terminal service session.

Children
No Data