Get-WMIObject Win32_ComputerSystem UserName returns null for RDP user

Russell Ramey 26 Reputation points
2021-04-08T14:43:54.437+00:00

So I am writing a PowerShell script to pick up some info from domain machines and one of the things that I want to correlate with is logged on user. In theory that is

(Get-WmiObject -ComputerName $CompName -ClassName Win32_ComputerSystem).username

...and it works just fine for locally logged in users. HOWEVER, it returns null for an RDP logged in user and I can't find any other way to get that information.

Has anyone got a clue how to get that info for an RDP logged in User?

This is all Active Directory 2016 with Win 10 1909 or later clients

Windows 10
Windows 10
A Microsoft operating system that runs on personal computers and tablets.
10,614 questions
Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,362 questions
0 comments No comments
{count} votes

Accepted answer
  1. Ian Xue (Shanghai Wicresoft Co., Ltd.) 29,571 Reputation points Microsoft Vendor
    2021-04-09T03:31:16.68+00:00

    Hi,

    You can try query user

    query user /server:$servername  
    

    Best Regards,
    Ian Xue

    ============================================

    If the Answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful