I have exports from two systems in two separate csv files.
These files contain a lot of different data but just to keep the question simple let's say one of them contains the email and username and the other one contains mobile numbers and email.
What I want to do is run a foreach loop that updates an attribute in the ad and within the loop run an another foreach loop to update the mobile number in the ad.
How can I match the email from the first list in the second nested foreach loop and get the row?
The script I already wrote:
$users = import-csv -path C:\temp\list1.csv
$users2 = import-csv -path c:\temp\list2.csv
Foreach ($user in $users) {
try {
$aduser = get-aduser -Filter "mail -eq '$($user.mail)'" -properties *
}
catch {
$aduser = $null
Write-host "No aduser found"
Continue
}
if ($user.username -ne $aduser.EmployeeID) {
set-aduser $aduser -EmployeeID $user.username
}
Foreach ($user2 in $users2) {
if ($user.mobile -ne $aduser.mobile) {
set-aduser $aduser -MobilePhone $user.mobile
}
}