Skip to content

Commit 4e163f4

Browse files
committed
2 parents 6e94859 + a926571 commit 4e163f4

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

Active Directory/Get-AllADSIDHistorySourceDomains.ps1

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,19 @@
2727
Write-Verbose -Message "Beginning ${MyInvocation.InvocationName}..."
2828
}
2929

30+
$SIDHistoryList = [ordered]@{}
3031
$DomainSIDs = New-Object -TypeName System.Collections.Generic.List[System.String]
3132
} # end begin
3233

3334
process {
3435
# Get all ActiveDirectory objects that have SID history.
35-
$AllSIDHistory = Get-ADObject -Filter { SIDHistory -like '*' } -Properties SIDHistory | Select-Object -ExpandProperty SIDHistory
36+
$ADObjectsWithSIDHistory = Get-ADObject -Filter { SIDHistory -like '*' } -Properties SIDHistory | Select-Object * -ExpandProperty SIDHistory
3637

37-
foreach ($SID in $AllSIDHistory) {
38-
$DomainSIDs.Add($SID.Substring(0, $SID.LastIndexOf('-')))
38+
foreach ($object in $ADObjectsWithSIDHistory) {
39+
# Create a hash table of DistinguishedName and SIDHistory for each object.
40+
$SIDHistoryList.Add($object.DistinguishedName, $object.SIDHistory)
41+
# Create a de-duplicated list of source domain SIDs from the SIDHistory attribute of each object.
42+
$DomainSIDs.Add( $($object.SIDHistory.Substring(0, $SID.LastIndexOf('-'))) )
3943
}
4044
} # end process
4145

0 commit comments

Comments
 (0)