Need to know user name from computer name in AD

Zaheer Ahmad 0 Reputation points
2024-08-25T06:06:52.26+00:00

Dear Respectable,

I have a computer name and IP address, i need to know which user is associated with that computer.

I tried to look into logon events e.g Event ID: 4624 etc, but there is only computername and ip. i couldn't find username there.

i don't have any third party tool like manageengine, so i am relying on windows powershell and eventviewer.

Can anyone advise how i can get user associated with that specific computer?

Thanks

Windows for business Windows Client for IT Pros Directory services Active Directory
Windows for business Windows Server User experience PowerShell
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. MotoX80 36,291 Reputation points
    2024-08-25T15:44:58.4066667+00:00

    You may need to add additional auditing options.

    https://woshub.com/check-user-logon-history-active-directory-domain-powershell/

    See also:

    https://learn.microsoft.com/en-us/answers/questions/514049/get-loggedonuser-computername-to-all-computers

    Your users aren't logging in with a local account, are they? That won't show up on your domain controllers.

    1 person found this answer helpful.

  2. Rich Matheisen 47,901 Reputation points
    2024-08-25T20:04:31.7066667+00:00

    Here's an example of getting those events:

    $q = @'
    <QueryList>
      <Query Id="0" Path="Security">
        <Select Path="Security">
          *[System[(EventID=4624)] and EventData[Data[@Name='LogonType'] and (Data='2' or Data='7')]]
        </Select>
      </Query>
    </QueryList>
    '@
    
    Foreach ($login in Get-WinEvent -FilterXml $q){
        $y = $login | Convert-EventLogRecord
        [PSCustomObject]@{
            LogonType = $y.LogonType
            SubjectDomainName = $y.TargetDomainName
            SubjectUserName = $y.TargetUserName
        }
    }
    
    

    This works on a local machine, you may need to make adjustments for working with the domain-level security logs.

    The query looks for Interactive logons and "Unlock" type logons. Adjust the query to get the logon types you're interested in.

    For your own sanity, it would be a good idea for you to install the PowerShell module PSScripTools and make use of the Convert-EventLogRecord. You don't have to, but without it you'll have to work with the XML found in the EventLorRecord you get back from the Get-WinEvent cmdlet.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.