How to Get Username from SID in PowerShell and CMD?
In this short tutorial, I will show you how to get the username from SID in PowerShell as well as in the command prompt (CMD).
Security Identifiers (SIDs) serve as unique identifiers for user accounts, groups, and system elements within the Windows operating system.
While SIDs are essential for system-level identification, they are often cryptic and challenging to interpret. Fortunately, PowerShell and Command Prompt offer straightforward methods to decode SIDs into user-readable usernames.
PowerShell get username from SID
PowerShell, with its extensive capabilities for system administration, offers a straightforward way to convert SID to username.
To get a username from SID in PowerShell, you can use the ‘System.Security.Principal’ class.
$sid = 'S-1-5-21-4145422188-3314407151-3568712334-1003'
(Replace ‘S-1-5-21-4145422188-3314407151-3568712334-1003’, with the SID you wish to convert.)
$sidObject = New-Object System.Security.Principal.SecurityIdentifier($sid)
Use Translate to Get user from SID
$sidObject.Translate([System.Security.Principal.NTAccount]).Value
You’ll see the username as the output in the PowerShell terminal.
SID to username using CMD
You can use the “wmic” command in the command prompt to get the username from SID.
wmic useraccount where sid='S-1-5-21-4145422188-3314407151-3568712334-1003' get name, caption
The above command will locate the given SID and return the name and caption of the user.
Just make sure to replace the ‘S-1-5-21-4145422188-3314407151-3568712334-1003’ with the SID you wish to convert.
Conclusion
Converting SIDs to usernames is pivotal for various administrative tasks in Windows environments.
PowerShell provides an efficient way to translate SIDs into readable usernames using the “System.Security.Principal” class. Whereas, in Command Prompt you can leverage “wmic” to get username from SID.
If you like this post, then follow CenturyBuzz on Facebook and X (Twitter) for more reviews, tips and tutorials.