I need to compile a text file which has the following entries for groups in my domain having a sidhistory attribute. Over many migrations, we have groups having multiple SIDhistory values. The text file needs to look like the following for a group having 3 sidhistory values with each entry on a separate line:
S-1-5-21-1144065412-1993610285-1348768671-2548,S-1-5-21-1454430755-160824244-2817426031-28398
S-1-5-21-2037530647-159734737-1230779191-2313,S-1-5-21-1454430755-160824244-2817426031-28398
S-1-5-21-1417001333-1682526488-839522115-261812,S-1-5-21-1454430755-160824244-2817426031-28398
As you can see, I have 3 old sids being mapped to a single new sid.
The problem I have is that all three lines are contained in a single line with each line mashed into the next entry.
Please let me know how I should amend my code below to get the desired result. I have tried using hash tables and also indexing the $Sidhistory array with the [$j] and I get “Unable to index into an object of type System.String”.
#First gather all the groups in the applicable OU which contain a SIDHistory
$Newgroups = Get-ADGroup -Filter {SIDHistory -ne “$null”} -SearchBase “OU=Security Groups,OU=Groups,dc=domain,dc=com” -ResultPageSize 1000 -Server dc1.domain.com -Properties SID,SIDHistory,accountNameHistory,DisplayName
$SIDMap = @()
Foreach ($grp in $Newgroups) {
$QtyofSIDs = $grp.SIDHistory.Count
$SIDHistoryTemp = @()
For ($j=0; $j -lt $QtyofSIDs; $j++) {
$temp1 = $grp.SIDHistory.Value[$j]
$temp1 = $temp1.value
$temp2 = “$temp1” + “,” + “$($grp.SID.Value)”
$SIDHistoryTemp += $temp2
}
$SIDMap += $SIDHistoryTemp
}