Sunday, December 12, 2010

Home / PowerShell Script - Search Active Directory and Generate SIDHistory Report

PowerShell Script - Search Active Directory and Generate SIDHistory Report

Updated script – with Multi-value support.  http://portal.sivarajan.com/2011/04/sidhistory-report-with-multi-value.html

This PowerShell Script can used to search a user object in Active Directory domain and generate a report with their SIDHistory value.

image

As you can see in the following screenshot, the output file (userinfo.txt) contains the SamAccontName and its SIDHistory value:  

image

When a User object migrated from one domain to another, a new SID must be generated for the user account and stored in the ObjectSID property.  Before the new value is written to the property, the previous value (ObjectSID from source domain) is copied to another property of a User object, sIDHistory in the Target domain. So you can use the sIDHistory value to search the Source domain using the ObjectSID attributes to identify the corresponding user in the Source domain.  In other words, the sIDHistory value will be  equal to the source ObjectSID. 

image

Search sIDHistory value of a migrated user using DSQUERY and identify the corresponding ObjectSID in the source domain. 

[image_thumb29[2].png]

Download: http://www.sivarajan.com/scripts/

More Scripts: http://www.sivarajan.com/scripts.html

SS

Santhosh Sivarajan

Microsoft MVP · Identity & Cybersecurity Architect

Santhosh has 30+ years of hands-on enterprise experience in Identity and Access Management, Microsoft Entra ID, Active Directory, Microsoft 365 and Zero Trust architecture. He is the author of two books on Windows Server and security, and leads consulting, assessments and training at SAG Business Group.

15 comments:

instead of the sidhistory, I want to export SID. but cant get it working. can you help me out?

Is there a way I can get the SIDs of all users in active directory and export as csv file?

That is easy. Instead of SIDHistory attribute use ObjectSID

Here is the modified PowerShell Script:


$UserInfoFile = New-Item -type file -force "C:\Scripts\UserInfo.csv"
"SamAccountName`tSID" | Out-File $UserInfoFile -encoding ASCII
$ObjFilter = "(&(objectCategory=User)(ObjectClass=user))"
$objSearch = New-Object System.DirectoryServices.DirectorySearcher
$objSearch.PageSize = 5000
$objSearch.Filter = $ObjFilter
$objSearch.SearchRoot = "LDAP://dc=sivarajan, dc=com"
$AllObj = $objSearch.FindAll()
foreach ($Obj in $AllObj)
{
$objItemT = $Obj.Properties
$tsam = $objItemT.samaccountname
$tsid = $objItemT.objectsid
write-host $tsam
write-host $tsid
"$tsam`t$tsid" | Out-File $UserInfoFile -encoding ASCII -append

}



You can use DSQUERY Command also:

dsquery * -filter "(&(objectCategory=User)(ObjectClass=user))" -attr samaccountname objectsid -limit 0 >> output.txt

Hi
If a user has more than one SidHystory entry, the script fill fail. Any ideas?



Cannot convert the "System.Byte[]" value of type "System.Byte[]" to type "System.Byte".
At line:16 char:4
+ $objectSID = [byte[]]$objpath1.sidhistory.value
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [], RuntimeException
+ FullyQualifiedErrorId : ConvertToFinalInvalidCastException

I have a different version of the script to support multi value

http://portal.sivarajan.com/2011/04/sidhistory-report-with-multi-value.html

Hello,
after exporting sidhistory, i want to delete them. A idea?
Thank you for help

In my opinion, it will be useful for students to find out more about https://essaydragon.com/essay-writing-service
This is one of my fav writing services.

Hi! I am looking to pull user details on a specific domain for each SIDHistory! Any idea what the command might be? I did try this : get-adobject -Filter * -Properties*| where{$_.objectSid -eq $SID}
but it gets stuck! doesn't proceed any further.

I have been using the services of essay typer for a very long time. Over the years, the use has not experienced any problems: everything always came on time and of excellent quality.

I have been looking for a Chinese wife for a long time, and only the chinese mail order brides service helped me in this desire. In a couple of minutes I was picked up a few options. I am very glad that there are such sites.

I myself like to do programming, and record video lessons about it. And the software from movavi helps me with this https://www.movavi.com/support/how-to/enhance.html. If you want to record high-quality video clips, then follow the link.

I gotta favorite this site it seems extremely helpful very helpful 토토

Post a Comment

Popular Posts
Workstation Trust Relationship Issue Issue: You receive the following error message, when you try to login to the domain.  The security database on the server does not have ... ADMT Service Account - Permission and Configuration The ADMT service account needs to have proper permission in source and target domains.  You don’t need to use 2 separate accounts.  You can ... My First Peek into Microsoft Exchange 2010 By Santhosh Sivarajan Before I really dive into Exchange 2010, I thought I would install and play with it first. I took some screen shots and notes during the ins... ObjectSID and Active Directory What is an objectSID in Active Directory? When a new object is created in Active Directory, Domain Controller assigns a unique value used ... AD Group Report - List Group Members in Active Directory–PowerShell Script Updated Script - http://portal.sivarajan.com/2011/10/search-ad-collect-local-admin-group.html Script #1 This script... Add Users to a Group–PowerShell Script Purpose – Add users to a group from an input file – PowerShell V2 Script.  Input file – Input file (Users.csv) contains samAccountName in... User Account Migration and Merging – Part I (ADMT) Part I - User Account Migration and Merging Using ADMT Part II - User Account Migration and Merging Using QMM pre-creating user account ... User Account Migration and Merging – Part II (Quest Migration Manager) Part I - User Account Migration and Merging Using ADMT Part II - User Account Migration and Merging Using QMM Pre-creating user account in... Delete Stale or Inactive Computer Accounts from Active Directory Here is an easy way to identify and delete inactive or stale computers in an Active Directory environment.  Using the dsquery command you c... Converting PowerShell (PS1) to EXE / Standalone Application As we know, there many applications available to convert a PowerShell file to a standalone executable file.  Based on my experience, PowerSh...