Win32_ComputerSystem blank result

This topic contains 5 replies, has 2 voices, and was last updated by Profile photo of Don Jones Don Jones 5 months ago.

  • Author
    Posts
  • #45815
    Profile photo of Edward Hodge
    Edward Hodge
    Participant

    When running either command(s) listed below results vary, depending on the type of system (desktop / server / virtual box)

    Invoke-Command -ComputerName "PC Name" -ScriptBlock {Get-WmiObject win32_computersystem | Select-Object username, name}
    or
    Get-WmiObject Win32_Computersystem -ComputerName "PC Name" |select UserName

    Result:

    username :
    name : "PC Name"
    PSComputerName : "PC Name"
    RunspaceId : 02168a17-9063-40fd-9739-f740c57d82e2

    or

    UserName
    ——–

    The result for username shows up blank when either command is ran against a virtual PC / Server or a physical server (as a domain admin)

  • #45823
    Profile photo of Don Jones
    Don Jones
    Keymaster

    That's fairly normal, actually. The underlying data implementation is somewhat different due to the way clients and servers handle user sessions.

    On a client, you can only have one interactive ("console") user, so that's what gets returned. You'd get the same thing on an RDS machine – whoever is logged into the console. But on a typical server, nobody's ever logged into the console – so you get nothing. The class isn't intended (according to the docs) to return a list of all connected sessions.

    • #45835
      Profile photo of Edward Hodge
      Edward Hodge
      Participant

      Mr. Jones... still doesn't make sense. I'm logged into all 3 machines (PC, virtual and server). I have a physical desktop and a virtual desktop. I'm the only one logged into to both, but the command only returns a value for the physical and not the virtual.

  • #45848
    Profile photo of Don Jones
    Don Jones
    Keymaster

    So, two computers, one physical, one virtual, both running a client operating system? You had mentioned servers previously, so I'm a little confused on what you're dealing with. Perhaps you could provide more specifics?

    Machine 1: Windows 10, physical, logged in, returns username
    Machine 2: Windows 10, virtual, Remote Desktop'd in, returns blank

    Something like that?

  • #45854
    Profile photo of Don Jones
    Don Jones
    Keymaster

    OK, so that's the thing. When you Remote Desktop into a client, you're not connecting to the "console" session (although the "local console" is blanked out). You're connected to a Remote Desktop session. Win32_ComputerSystem doesn't include Remote Desktop connections, it only looks at the local console. The whole Username property of Win32_ComputerSession is a red herring inherited from the generic CIM_ComputerSystem reference – and it was intended for single-user operating systems, which Windows isn't. Microsoft implemented it the way the DMTF specification says to, but that doesn't really encompass what Windows actually does.

    If the broader goal here is, "I want to find out the one user who's logged in interactively," Windows makes that difficult, because all versions of Windows understand the concept of multiple logged-in users. Even though we think of them as "personal" computers with only one user, Windows doesn't see it that way. That's why System Center Configuration Manager had to implement this whole "affinity" concept – because Windows itself doesn't have that concept.

    You might try instead looking at Win32_Session, I think it is. You can look at the session type for each user to perhaps narrow down the ones you're interested in.

You must be logged in to reply to this topic.