I have the results of two Get-ADUser
queries stored in variables (they are querying two Active Directories).
What is the best way to compare them looking for an specific attribute and export to a CSV if they match? I tried to get it to work using nested forEach
loops and comparing attributes with an if
but it just appended to the csv all the results from both AD.
I am not currently home and I will upload my current code when I arrive but in pseudocode it was like this:
$res1 = get-adUser -filter{enabled -eq $true} -Properties samAccountName, displayname, mail | select-object samAccountName, displayname, mail
$res2 = get-adUser -server ABC -filter{enabled -eq $true} -Properties samAccountName, displayname, mail | select-object samAccountName, displayname, mail
ForEach($u1 in $res1){
ForEach($u2 in $res2){
If($u1.mail -eq $u2.mail){
Write-host $u1.mail $u2.mail
}
}
}