The script it grew out of, and why orphaned SIDs pile up in the first place, is in Understanding Orphaned SIDs in Active Directory.

01OrphanedSid: Find, Remove, Restore
I rebuilt my old Find-UnknownSID script as OrphanedSid, a PowerShell Gallery module with three commands, then ran the published 1.0.1 against a lab domain from discovery through removal and back.