PowerShell: Active Directory User to SID and SID to User

I was recently asked to find the username associated with a particular Active Directory SID (technically I was given the RID).

This is actually pretty easy in PowerShell, and quite intuitive using basic AD cmdlets.

Get the user for a given RID:

Get-ADUser -Filter * | Select-Object -Property SID,Name | Where-Object -Property SID -like "*-6640"

Get the SID for a given user:

Get-ADUser -Identity ad.user | Select-Object -Property Name,SID
This entry was posted in PowerShell, Windows and tagged , , , , , , , . Bookmark the permalink.

1 Response to PowerShell: Active Directory User to SID and SID to User

  1. Emmanuel says:

    Hi Robin,

    Get-ADUser -Identity S-1-5-21-2511372296-46634312-3923189056-2186

    Much faster :)

    If you need the SID portion, you can get it with :
    (Get-ADDomain).DomainSID

    So :
    Get-ADUser -Identity “$((Get-ADDomain).DomainSID.Value)-2186” is much more efficient in large environment :)

    Like

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.