Find Security Identifier (SID) of User in Windows  

    Find Security Identifier (SID) of User in Windows

    Find Security Identifier (SID) of User in Windows

    How to Find Security Identifier (SID) of User in Windows
    Published by Category: User Accounts
    01 Nov 2023
    Designer Media Ltd

    How to Find Security Identifier (SID) of User in Windows


    Sometimes, you need to know what the security identifier (SID) is for a specific user on the system.

    A SID is a string value of variable length that is used to uniquely identify users or groups, and control their access to various resources like files, registry keys, network shares etc. Each account has a unique SID that an authority, such as a Windows domain, issues. The SID is stored in the security database. When a user logs on, the system retrieves the user SID from the database, places the SID in the user access token, and then uses the SID in the user access token to identify the user in all subsequent interactions with Windows security. Each SID is a unique identifier for a user or group, and a different user or group cannot have the same SID.

    See also: Well-known security identifiers in Windows operating systems

    This tutorial will show you different ways on how to find the security identifier (SID) of a user account in Vista, Windows 7, Windows 8, and Windows 10.


    Contents

    • Option One: To Find SID of Current User using "WhoAmI" command
    • Option Two: To Find SID of Current User using "wmic useraccount" command
    • Option Three: To Find SID of All Users using "wmic useraccount" command
    • Option Four: To Find SID of Specific User using "wmic useraccount" command
    • Option Five: To Find User Name for SID using "wmic useraccount" command
    • Option Six: To Find SID of All Users using "Get-WmiObject" PowerShell command
    • Option Seven: To Find SID of Users using Registry Editor



    EXAMPLE: Security Identifier (SID) with account association
    Find Security Identifier (SID) of User in Windows-sid.gif






    OPTION ONE

    To Find SID of Current User using "WhoAmI" command


    1 Open a command prompt or PowerShell.

    2 Copy and paste the whoami /user command into the command prompt, and press Enter.

    Find Security Identifier (SID) of User in Windows-whoami_user.png






    OPTION TWO

    To Find SID of Current User using "wmic useraccount" command


    1 Open a command prompt.

    2 Copy and paste the wmic useraccount where name='%username%' get domain,name,sid command into the command prompt, and press Enter.

    Find Security Identifier (SID) of User in Windows-wmic_useraccount-2.png






    OPTION THREE

    To Find SID of All Users using "wmic useraccount" command


    1 Open a command prompt or PowerShell.

    2 Copy and paste the wmic useraccount get domain,name,sid command into the command prompt, and press Enter.

    Find Security Identifier (SID) of User in Windows-wmic_useraccount-1.png






    OPTION FOUR

    To Find SID of Specific User using "wmic useraccount" command


    1 Open a command prompt.

    2 Type the command below into the command prompt, and press Enter.

    wmic useraccount where name='username' get sid

    Substitute username in the command above with the actual user name (ex: "Brink") of the account you want to find the SID for.

    For example: wmic useraccount where name='Brink' get sid

    Find Security Identifier (SID) of User in Windows-wmic_useraccount-3.png






    OPTION FIVE

    To Find User Name for SID using "wmic useraccount" command


    1 Open a command prompt.

    2 Type the command below into the command prompt, and press Enter.

    wmic useraccount where sid='<sid>' get domain,name

    Substitute <sid> in the command above with the actual SID (ex: "S-1-5-21-237214570-1361766723-3061440971-1001") of the account you want to see the name for.

    For example: wmic useraccount where sid='S-1-5-21-237214570-1361766723-3061440971-1001' get domain,name

    Find Security Identifier (SID) of User in Windows-wmic_useraccount-4.jpg






    OPTION SIX

    To Find SID of All Users using "Get-WmiObject" PowerShell command


    1 Open PowerShell.

    2 Copy and paste the Get-WmiObject win32_useraccount | Select domain,name,sid command into the command prompt, and press Enter.

    Find Security Identifier (SID) of User in Windows-get-wmiobject_powershell.png






    OPTION SEVEN

    To Find SID of Users using Registry Editor


    This option has one limitation which is you can only get the SID of either a local user or a domain user who has logged in at least once onto this PC.


    1 Press the Win + R keys to open Run, type regedit into the command prompt, and click/tap on OK to open Registry Editor.

    2 Navigate to the key below in the left pane of Registry Editor. (see screenshot below)

    HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList

    3 Each of the items at this hive is named with the SID of the account. By looking at the ProfileImagePath value for each SID subkey, you can identify the account’s name.

    For example, the S-1-5-21-237214570-1361766723-3061440971-1001 SID key is for the user with the C:\Users\Brink profile folder path and Brink being the account name.

    Find Security Identifier (SID) of User in Windows-profilelist_registry.jpg


    That's it,
    Shawn Brink






  1. Posts : 93
    Windows 10
       #1

    Some useful SID related functions for script use. Also demonstrates how to retrieve SID information from .NET instead of WMI.
    Code:
    function Get-SidFromName ($user) {
        (New-Object System.Security.Principal.NTAccount($user)).Translate([System.Security.Principal.SecurityIdentifier]).Value
    }
    
    function Get-NameFromSid ($sid) {
        (New-Object System.Security.Principal.SecurityIdentifier($sid)).Translate([System.Security.Principal.NTAccount]).Value
    }
    
    function Get-CurrentUserSid {
        [System.Security.Principal.WindowsIdentity]::GetCurrent().User.Value
    }
    
    function Get-UserSidFromWildcard ($sid) {
        ([ADSI]"WinNT://$env:COMPUTERNAME").Children | ?{$_.SchemaClassName -eq 'User'} | %{(New-Object Security.Principal.SecurityIdentifier($_.objectSid.Value, 0)).Value} | ?{$_ -like $sid}
    }
    
    function Get-GroupSidFromWildcard ($sid) {
        ([ADSI]"WinNT://$env:COMPUTERNAME").Children | ?{$_.SchemaClassName -eq 'Group'} | %{(New-Object Security.Principal.SecurityIdentifier($_.objectSid.Value, 0)).Value} | ?{$_ -like $sid}
    }
    
    function Get-ServiceSidFromWildcard ($sid) {
        ([ADSI]"WinNT://$env:COMPUTERNAME").Children | ?{$_.SchemaClassName -eq 'Service'} | %{(New-Object Security.Principal.SecurityIdentifier($_.objectSid.Value, 0)).Value} | ?{$_ -like $sid}
    }
    
    function Get-SidFromWildcard ($sid) {
        ([ADSI]"WinNT://$env:COMPUTERNAME").Children | ?{'Group', 'User' -contains $_.SchemaClassName} | %{(New-Object Security.Principal.SecurityIdentifier($_.objectSid.Value, 0)).Value} | ?{$_ -like $sid}
    }
      My Computer


  2. Posts : 4,201
    Windows 10 Pro x64 Latest RP
       #2

    Shawn, There's also Mark Russinovich's tool PsGetSid
      My Computers


  3. Posts : 68,543
    64-bit Windows 11 Pro for Workstations
    Thread Starter
       #3

      My Computers


  4. Posts : 174
    Windows 10 Enterprise x64 1709
       #4

    WMIC UserAccount Where Name='%Username%' Get SID
    -
    This works perfectly but it only works in Command Prompt and not in a .bat file.
    I also cannot assign it to a string variable since it's not just SID and is a multi line string.
    I'm not very comfortable with batch files so what's the shortest and easiest way to store it in a variable to use in a batch file? :)
      My Computer


  5. Posts : 68,543
    64-bit Windows 11 Pro for Workstations
    Thread Starter
       #5

    Hello omidsolo, :)

    If you like, you could use the command in Option 1 or 3 in a .bat file.
      My Computers


 

Tutorial Categories

Find Security Identifier (SID) of User in Windows Tutorial Index Network & Sharing Instalation and Upgrade Browsers and Email General Tips Gaming Customization Apps and Features Virtualization BSOD System Security User Accounts Hardware and Drivers Updates and Activation Backup and Restore Performance and Maintenance Mixed Reality Phone


  Related Discussions
Our Sites
Site Links
About Us
Windows 10 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 10" and related materials are trademarks of Microsoft Corp.

© Designer Media Ltd
All times are GMT -5. The time now is 23:52.
Find Us




Windows 10 Forums