Fire up Windows PowerShell and run:

$strSID="S-1-5-21-500000003-1000000000-1000000003-1001"
$uSid = [ADSI]"LDAP://<SID=$strSID>"
echo $uSid

The output should look something like this,

distinguishedName : {CN=John Doe,OU=Domain Admins,OU=People,OU=xxx,DC=xxx}
Path              : LDAP://<SID=S-1-5-21-500000003-1000000000-1000000003-1001>
🌐
Microsoft Learn
learn.microsoft.com › en-us › powershell › module › activedirectory › get-aduser
Get-ADUser (ActiveDirectory) | Microsoft Learn
The Identity parameter specifies the Active Directory user to get. You can identify a user by its distinguished name (DN), GUID, security identifier (SID), or Security Account Manager (SAM) ...
Top answer
1 of 5
27

Fire up Windows PowerShell and run:

$strSID="S-1-5-21-500000003-1000000000-1000000003-1001"
$uSid = [ADSI]"LDAP://<SID=$strSID>"
echo $uSid

The output should look something like this,

distinguishedName : {CN=John Doe,OU=Domain Admins,OU=People,OU=xxx,DC=xxx}
Path              : LDAP://<SID=S-1-5-21-500000003-1000000000-1000000003-1001>
2 of 5
7

The "LDAP way" to do this would be to retrieve the base object with the GUID (or SID), which will retrieve only the base object and not have additional class data attached. However, from this base object you can retrieve the actual "distinguishedName" for the user object. Retrieving the user object using the "distinguishedName" attribute will return a DirectoryEntry object (.Net/C#/PowerShell) or a iadsUser object (VBScript) with full class data and allow you to get whatever other attribute data you need.

The issue is retrieving the initial object with the GUID (or SID). Some sources will say that you must convert the string format GUID (i.e., {28c67c50-9778-47a4-a77a-bf56f238a0c4}) into a string representation of the byte-array (i.e., "\50\7c\c6\28\78\97\a4\47\7a\a7\bf\56\f2\38\a0\c4") to pass to LDAP. According to Microsoft documentation this is not the case. A simple string representation of the GUID/SID is sufficient.

Here's a sample of how you can bind to the object via the GUID then retrieve the actual user object with full class data. Powershell actually pulls the complete object if you bind with the GUID. If you use VBScript, then you would need to do the two step process.

Also, please note that although the Microsoft docs say that multiple GUID-string formats are acceptable, the only one I have been able to successfully use is to strip the {}- characters. ALSO, please note this is NOT a correct "byte-array" string, but simply the GUID string stripped of special characters.

$strGUID = "{28c67c50-9778-47a4-a77a-bf56f238a0c4}" -replace '-|{|}',''
$guid = [ADSI]"LDAP://<GUID=$strGUID>"
$user = [ADSI]$guid.distinguishedName

The same process can be used for a SID bind. The MSDN page describing this says there are several fstring formats available, but the most common will be the S-1-5-...-...-...-... format.

#Powershell
$strSID="S-1-5-21-500000003-1000000000-1000000003-1001"
$uSid = [ADSI]"LDAP://<SID=$strSid>"
$user = [ADSI]$user.distinguishedName

*** QUERYING ***

If you are going to perform an LDAP query to find the object (e.g. by comparing 'objectGUID' to a byte-array or 'objectSID' to a byte-array), that is when you will need to do the "correct" byte-array conversion. It is important to note that the byte-array has a different order than the string representation, as it is stored as DWORD-WORD-WORD-WORD-BYTES for GUID, and DOES take endian order into consideration. Converting the byte-array for a SID has similar condierations.

There are several different ways to accomplish the conversion, Technet has a simple vbScript algorithm. You could also do something fancier with C#/VB.Net using the System.Guid, or via a simple script in PowerShell (gotta love PowerShell!):

#Powershell
#   Creates a new System.GUID object from the supplied string.
#   Only need for this example.
$guid = [system.guid]"{28c67c50-9778-47a4-a77a-bf56f238a0c4}" 
$out=""
#Formats the array of integers as a backslash-delimited string of Hex values
$guid.ToByteArray() | %{ ("\{0:x2}" -f $_) }

You should then be able to query for the object using a standard LDAP filter:

(&(objectClass=User)(objectGUID=\50\7c\c6\28\78\97\a4\47\a7\7a\bf\56\f2\38\a0\c4))

... or whatever else you may be querying for. This should work for a SID as well.

Discussions

How to find user or group from SID - Software & Applications - Spiceworks Community
Under my Namespaces > domain.local\folder > delegation tab, under user or group i have a SID displayed instead of a username/group. How do I determine what this is? I have tried Get-ADUser -Identity SID here and Get-ADGroup -Identity SID Here Both return no results, how do i find out what this ... More on community.spiceworks.com
🌐 community.spiceworks.com
6
July 19, 2017
How do I use get-aduser "username" | select SID to get only the output, not the header, so i can use it in a variable

I always wrap the command in parenthesis and specify the property I want. It works for one or many objects, and is more simple than writing select -expand statements.

$SID = (Get-ADUser "Username").SID
More on reddit.com
🌐 r/PowerShell
11
4
January 24, 2018
get SID for all users in AD
$props = @("sn", "givenname", ... write-host "this is the sid:$sid" write-host $item.SID ... The property name, I think, should be objectSID. Also, why are you using "ADquery" instead of the PowerShell Get-ADUser?... More on learn.microsoft.com
🌐 learn.microsoft.com
3
0
February 22, 2022
Get-aduser with specific SIDHistory
Get-ADUser -Filter * -Properties * It's this line right here that's gumming up the works. You're requesting all properties and all users. Need to set a more granular filter. Get-ADUser -Filter {SIDHistory -like $SID} -Properties SIDHistory | Select Name,Enabled,SIDHistory | Export-Csv "x.csv" SIDHistory might be a multi-value property, so it's possible you'll have to -join it in the select. More on reddit.com
🌐 r/PowerShell
8
4
March 1, 2021
People also ask

How do I convert a Windows SID to a username using PowerShell?
Run this command: (New-Object System.Security.Principal.SecurityIdentifier("S-1-5-21-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-1001")).Translate([System.Security.Principal.NTAccount]).Value. Replace the SID string with the actual SID you are investigating. This returns the DOMAIN\Username format. If the command throws an IdentityNotMappedException, the account has been deleted from Active Directory or the local SAM database. For deleted accounts, check the AD Recycle Bin with Get-ADObject -Filter {objectSid -eq "S-1-5-21-..."} -IncludeDeletedObjects if it is enabled. For accounts from untrusted domains
🌐
blumira.com
blumira.com › blog › how-to-find-a-user-with-their-security-id-in-windows
Find a User with Their Security ID in Windows | Blumira
How do I find all SIDs associated with a specific user account?
For the currently logged-in user, run whoami /user to see the primary SID, or whoami /all to see the primary SID plus all group SIDs the token contains. For all local accounts on a machine, use wmic useraccount get name,sid (or Get-LocalUser | Select-Object Name,SID in newer PowerShell). For domain accounts, use Get-ADUser -Identity username -Properties SID,SIDHistory to retrieve both the current SID and any SID history entries (which appear after domain migrations). SID history is important during investigations because a user who has been migrated between domains carries old SIDs that still
🌐
blumira.com
blumira.com › blog › how-to-find-a-user-with-their-security-id-in-windows
Find a User with Their Security ID in Windows | Blumira
Why do Windows security logs show SIDs instead of usernames?
Windows logs the SID at the time the event occurs because SIDs are immutable identifiers. Username resolution happens at display time when you view the event, not when the event is recorded. If the account has been deleted or renamed since the event was logged, the SID remains in the raw event data but the display name lookup fails. This is why you often see unresolved SIDs in older log entries or on systems that have lost trust with the domain controller. It also happens when events reference accounts from external or untrusted domains. The log viewer (Event Viewer, PowerShell, or your SIEM)
🌐
blumira.com
blumira.com › blog › how-to-find-a-user-with-their-security-id-in-windows
Find a User with Their Security ID in Windows | Blumira
🌐
Spiceworks
community.spiceworks.com › software & applications
How to find user or group from SID - Software & Applications - Spiceworks Community
July 19, 2017 - Under my Namespaces > domain.local\folder > delegation tab, under user or group i have a SID displayed instead of a username/group. How do I determine what this is? I have tried Get-ADUser -Identity SID here and Get-ADGroup -Identity SID Here Both return no results, how do i find out what this ...
🌐
Reddit
reddit.com › r/powershell › how do i use get-aduser "username" | select sid to get only the output, not the header, so i can use it in a variable
r/PowerShell on Reddit: How do I use get-aduser "username" | select SID to get only the output, not the header, so i can use it in a variable
January 24, 2018 -

Hello All,

My question is this, i'm using the following:

get-aduser "username" | select SID

In an effort to get the SID of a user so I can plug it in as a variable down the line...the problem is it keeps coming up as the SID with @{SID= preceding it.

Obviously...that is not helping me when I try to just plugin the ACTUAL SID number into a variable later in the script. Is there a better way to do this so I can just get the actual text of the SID as an output?

Any help is appreciated!

🌐
Active Directory Reporting Tool
activedirectorypro.com › find-user-sid-in-active-directory
How to Find User SID in Active Directory - Active Directory Pro
July 3, 2025 - See below for more examples. Step 1. Open PowerShell · Step 2. Run the following command. get-aduser -Identity username | select name, SID · You can see below the users SID in the red box.
Find elsewhere
🌐
Blumira
blumira.com › blog › how-to-find-a-user-with-their-security-id-in-windows
Find a User with Their Security ID in Windows | Blumira
October 26, 2022 - For all local accounts on a machine, use wmic useraccount get name,sid (or Get-LocalUser | Select-Object Name,SID in newer PowerShell). For domain accounts, use Get-ADUser -Identity username -Properties SID,SIDHistory to retrieve both the current ...
🌐
Reddit
reddit.com › r/powershell › get-aduser with specific sidhistory
r/PowerShell on Reddit: Get-aduser with specific SIDHistory
March 1, 2021 -

Hi all,

I have scirpt which getting all users\groups with specific sidhistory value.

$SID = "S-1-5-21-xxxxx-xxxxx-xxxx*"

Get-ADUser -Filter * -Properties * | where{$_.sidhistory -like $SID} | Select-Object Name, @{N='Enabled';E={$_.Enabled}}, @{N='SIDHistory';E={$_.SIDHistory}}, | export-csv "x.csv"

However,

script not getting all users\groups. It's query to tens of thousands of items. Perhaps there is a problem.

Do you have better idea of this script?

Top answer
1 of 3
2
Get-ADUser -Filter * -Properties * It's this line right here that's gumming up the works. You're requesting all properties and all users. Need to set a more granular filter. Get-ADUser -Filter {SIDHistory -like $SID} -Properties SIDHistory | Select Name,Enabled,SIDHistory | Export-Csv "x.csv" SIDHistory might be a multi-value property, so it's possible you'll have to -join it in the select.
2 of 3
2
You can't do a wildcard search on Security Identifiers using AD module Filter or LDAPFilter, if you know the specific SID you're looking for you can do: Get-ADobject -LDAPFilter "(sidHistory=$SID)" -properties sidHistory|select Enabled, @{N='SIDHistory';E={$_.SIDHistory.Value}}|Export-Csv x.csv -NoTypeInformation If you don't know the specific SID or you want to use a wildcard then there are several ways of doing this, one of the most efficient ones is: $SID = "S-1-5-21-xxxxx-xxxxx-xxxx*" $Result=New-Object System.Collections.ArrayList filter matchSID{ if($_.sidHistory.Value -like $SID) { $Result.Add( [pscustomobject]@{ Name=$_.Name SIDHistory=$_.SIDHistory.Value Enabled=$_.Enabled }) > $null } } Get-ADuser -Filter * -Properties sidHistory|matchSID if($Result) { $Result|Export-Csv x.csv -NoTypeInformation } Using a PS Filter and an ArrayList to store the results in memory is a lot more efficient than using the Where-Object and disk I/O each time you find a result in this case, also never ever call all the properties for each user, only the properties you want to bring.
🌐
Gregorystrike
gregorystrike.com › 2014 › 01 › 30 › how-to-search-active-directory-by-objectsid-using-powershell
How to Search Active Directory by 'objectSid' using PowerShell
January 30, 2014 - I wanted to re-apply the NTFS permissions on the replaced drive so I needed to know which each SID belonged to. Run the following on a computer that is a member of the domain: Import-Module ActiveDirectory Get-ADUser -Identity S-1-5-21-941005169-1824062477-405670111-1106
🌐
Infrasos
infrasos.com › home › blog › find sid in active directory users and computers using powershell
Get SID in Active Directory Users and Computers Powershell
April 14, 2025 - We can get active directory user SID using the Get-ADUser cmdlet, bringing one or more AD user account details.
🌐
Hotdocs
help.hotdocs.com › hotdocshub › onpremise › 1.19.0 › help › admin › Find_the_SID_of_an_Active_Directory_user.htm
HotDocs Hub Admin Guide - Find the SID of an Active Directory user
A SID is a unique ID that identifies ... administrator. Run the Windows Command Prompt as an administrator. Type the following command: wmic useraccount where name='{username}' get sid Where username is the Active Directory username for the user you want to use as the Hub root ...
🌐
ShellGeek
shellgeek.com › home › powershell tips › powershell – get user sid in active directory
PowerShell - Get User SID in Active Directory - ShellGeek
April 14, 2024 - Run the following script to retrieve the sid of a user. Get-AdUser -Identity toms | Select Name, SID, UserPrincipalName
🌐
GitHub
gist.github.com › 48a88ac982e9e09ff2c9
get an AD user from a sid · GitHub
get an AD user from a sid · Raw · get-aduserbysid.ps1 · This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
🌐
NinjaOne
ninjaone.com › home › blog › it ops › how to find the security identifier (sid) of users in windows
How to Find the Security Identifier (SID) of Users in Windows
March 14, 2025 - Get-LocalUser | Select Name,SID → Lists local user SIDs. Get-ADUser -Identity username -Properties SID → Retrieves an Active Directory user SID.
🌐
Windows OS Hub
woshub.com › convert-sid-to-username-and-vice-versa
How to Convert SID to User/Group Name and User to SID | Windows OS Hub
August 27, 2025 - When searching for objects by a known SID in an AD domain, it is better to use the Get-ADObject cmdlet. This is a universal method for searching objects in the Active Directory domain by SID when you don’t know the type of AD object to which the SID belongs or which cmdlet to use to find it (Get-AdUser, Get-ADComputer, or Get-ADGroup),
Top answer
1 of 2
2

You can do something like the following:

$domains = Get-ADForest | Select-Object -ExpandProperty Domains
$SID = 'some sid value'
$CN = 'user CN'
foreach ($domain in $domains) {
    $DC = (Get-ADDomainController -DomainName $domain -Discover).Hostname
    $User = Get-ADObject -filter "CN -eq '$CN' -and ObjectSID -eq '$SID'" -Server $DC -IncludeDeletedObjects -Credential $mycred -ErrorAction SilentlyContinue
}

Explanation:

  • You can list all of your subdomains using the Get-ADForest command, and that collection is stored in $domains.
  • A foreach loop can loop through each of those domains with the current domain being $domain.
  • For each domain, you can query for a domain controller to store in $DC and then perform a Get-ADObject with the -IncludeDeletedObjects.
  • To speed up your query, you can use the -filter switch rather than piping to Where-Object.
  • You can filter on the CN and ObjectSID attributes.

Additional Considerations:

In this script, nothing is being done with the discovered data. I am not sure where you want to go from here. You will need to add some other logic like an if statement to check the value of $User. Because we are using -filter, $user will be $null if no object is found rather than throwing an error, which you will see when using Get-ADObject -Identity. From there you can do additional processing even if that means utilizing break statements.

if ($user) {
    # User was found. Process code here.
    break # Exit the foreach loop because further loop processing is not needed
}
else {
    # User was not found. Process code here
}

No output is generated in the solution because all queried data is stored in variables. The value of $DC and $User will be overwritten during each loop iteration. It may be best to store the discovered user data in a collection with a specific set of properties. You could retrieve DistinguishedName or CanonicalName along with SamAccountName and ObjectSID to know which domain and container has the user object.

$Users = foreach ($domain in $domains) {
    $DC = (Get-ADDomainController -DomainName $domain -Discover).Hostname
    Get-ADObject -filter "CN -eq '$CN' -and ObjectSID -eq '$SID'" -Server $DC -IncludeDeletedObjects -Properties CanonicalName,SamAccountName,ObjectSID -Credential $mycred -ErrorAction SilentlyContinue |
        Select-Object SamAccountName,ObjectSID,CanonicalName
}

In the code snippet above, $users will now contain a collection of found users with the SamAccountName,ObjectSID,CanonicalName properties for each object.

Like Get-ADUser, Get-ADObject has a limited set of default display properties. You will need to use the -Properties parameter to display what you require. You can test what is available by starting with -Properties *.

Not much information has been provided on how AD user data is being input into the script. You may have a collection of CN values or CSV file. You will have to consider how to iterate over those values.

2 of 2
0

I might be wrong, but you can call the WMI Win32_SID class with the SID = as parameter. Works for me with two-way trusts.

🌐
TheITBros
theitbros.com › active directory › how to find a user's sid in active directory – theitbros
How to Find a User’s SID in Active Directory (PowerShell & CMD Guide)
January 6, 2026 - Get-ADUser -Identity S-1-5-21-482871169-3907970989-1540170358-1108 · If you don’t know what type of object the SID belongs to, you can use the Get-ADObject cmdlet to find the type and name of the Active Directory object by its ID: