Every Windows user, computer, or service account has a unique alphanumeric identifier called the security ID (SID).
Windows security-related processes, such as authentication, authorization, delegation, and auditing, use SIDs to uniquely identify security principals.
A security principal is any entity that can be authenticated by the operating system, such as a user account, a computer account, or a thread or process that runs in the security context of a user or computer account, or the security groups for these accounts.
A SID is a Security Identifier. It’s the “primary key” for any object in an Active Directory. For example, users have SIDs, as do Printer objects, Group objects, etc. SID‘s are unique to a Domain.
To illustrate, let us analyze an example SID that I retrieved from my test Active Directory (AD) system:
S-1-5-21-4064627337-2434140041-2375368561-1036. All SID fields have a specific meaning; so, for the above sample SID:
<aside> ⚠️ The SID of an AD domain account is created by a Domain’s Security authority that runs on every Windows domain controller (DC)
The SID of a local account is created by the Local Security Authority (LSA) service that runs on every Windows box.
</aside>
Below some useful powershell code to retrieve SID and RID of domain users:
# Replace 'username' with the actual username of the user you want to retrieve the SID for
$username = 'fcastle'
# Retrieve the user using Get-ADUser and then access the SID property
$user = Get-ADUser -Identity $username
if ($user) {
$userSID = $user.SID
Write-Host "SID of $username is: $userSID"
} else {
Write-Host "User $username not found."
}