Hi,
The goal is given a set of user accounts with their mail attribute, determine if that mail value exists in the mail attribute of a different user (ie. SamaccountName) account. Below, after the both hashtables are loaded, I use ContainsValue to search
in the the hashtable of AllDomainUsers. How does ContainsValue work if multiple accounts contain the same mail attribute value? So my search is really for any account in AllDomainUsers which contains the mail attribute for the SamAccountName in
$AllUsers. I've successfully accomplished this using IFs and arrays, but the performance is slow when the arrays are large.
$AllUsers = Get-Aduser -Filter .... -Pr mail
$AllUsersHash = $null
$AllUsersHash = @{}
Foreach ($AllU in $AllUsers) {
$AllUsersHash.add($AllU.SamAccountName,$AllU.Mail)
}
$AllDomainUsers = Get-Aduser .... * -Pr mail
$hash = $null
$hash = @{}
Foreach ($AU in $AllDomainUsers) {
$hash.add($AU.SamAccountName,$AU.Mail)
}
Foreach ($item in $AllUsersHash.GetEnumerator()) {
$hash.ContainsValue("$item.Value")
}
&