Getting the Username from the HKEY_USERS values

前端 未结 9 1021
予麋鹿
予麋鹿 2021-01-30 04:08

Is there a way to connect between the values under HKEY_USERS to the actual username?
I saw some similar questions, but most (if not all) talks about C# code, and my need is

9条回答
  •  [愿得一人]
    2021-01-30 04:56

    You can use the command PSGetSid from Microsoft's SysInternals team.

    Download URL: http://technet.microsoft.com/en-gb/sysinternals/bb897417.aspx

    Usage:

    psgetsid [\\computer[,computer[,...] | @file] [-u username [-p password]]] [account|SID]
    -u  Specifies optional user name for login to remote computer.
    -p  Specifies optional password for user name. If you omit this you will be prompted to enter a hidden password.
    Account PsGetSid will report the SID for the specified user account rather than the computer.
    SID PsGetSid will report the account for the specified SID.
    Computer    Direct PsGetSid to perform the command on the remote computer or computers specified. If you omit the computer name PsGetSid runs the command on the local system, and if you specify a wildcard (\\*), PsGetSid runs the command on all computers in the current domain.
    @file   PsGetSid will execute the command on each of the computers listed in the file.
    

    Example:

    psgetsid S-1-5-21-583907252-682003330-839522115-63941
    

    NB:

    • Where the user is a domain/AD(LDAP) user, running this on any computer on the domain should give the same results.
    • Where the user is local to the machine the command should either be run on that machine, or you should specify the computer via the optional parameter.

    Update

    If you use PowerShell, the following may be useful for resolving any AD users listed:

    #create a drive for HKEY USERS:
    New-PSDrive -PSProvider Registry -Name HKU -Root HKEY_USERS -ErrorAction SilentlyContinue
    
    #List all immediate subfolders
    #where they're a folder (not a key)
    #and they's an SID (i.e. exclude .DEFAULT and SID_Classes entries)
    #return the SID
    #and return the related AD entry (should one exist).
    Get-ChildItem -Path 'HKU:\' `
    | ?{($_.PSIsContainer -eq $true) `
    -and ($_.PSChildName -match '^S-[\d-]+$')} `
    | select @{N='SID';E={$_.PSChildName}} `
    , @{N='Name';E={Get-ADUser $_.PSChildName | select -expand Name}}
    

    You could also refine the SID filter further to only pull back those SIDs which will resolve to an AD account if you wished; more on the SID structure here: https://technet.microsoft.com/en-us/library/cc962011.aspx

提交回复
热议问题