I'am not able to have this script to working as expected. Please see below
i have two arrays $newusers and $oldusers with below data in each
$newusers = fadbd34|Alan Simon|Jones,ken A
fadbk45|Alice Lund|Dave,John h
fadoo78|Nathan Hugh|Trot,Carol M
fadt359|Jon Hart|Jones,Karen D
fafyl38|Miley Mcghee|Main,Josh D
abbrt86|Andrew Hayden|Mary,Martin G
frt5096|Andrew Cork|Kain,Martha E
ikka155|Andrew Mullen|Raymond, Gavin G
Note: Please observe the last 3 users from $newusers are not there in $oldusers
$oldusers = fadbd34|Alan Simon|11754
fadbk45|Alice Lund|11755
fadoo78|Nathan Hugh|11755
fadt359|Jon Hart|11755
fafyl38|Miley Mcghee|11732
Now, i'am trying to write a script that checks if the first field(Userid) from $newusers is traced in $oldusers then join fields $newusers[0],$newusers[1],$oldusers[2], $newusers[2]into $Activeusers array and for the new userid's not found in $oldusers join $newusers[0], $newusers[1], $newusers[2] into $Inactiveusers array. I'am getting incorrect results. Below is so far i can came up with.
$Activeusers = @()
$Inactiveusers = @()
foreach ($nrow in $newusers) {
foreach ($orow in $oldusers){
($idNew,$newusrname,$mgr) = $newrow.split('|')
($idOld,$oldusrname,$costcntr) = $oldrow.split('|')
if ( $idOld[0] -ieq $idOld[0]){
$Activeusers += [string]::join('|',($idNew[0],$nusrname[1],$cstcntr[2],$mgr[2]))
} else {
$Inactiveusers += [string]::join('|',($idNew[0],$nusrname[1],$mgr[2]))
}
}
}