I have been tasked to write a powershell script that will take the data from 2 CSVs and information from Active Directory and send the output to a separate CSV. The unfortunate part is that there is no unique single column for each of the CSVs and I will need to query AD using first name and last name. The only consistent data across all 3 is the first name and last name.
I think it comes down to two questions.
How do I merge the 2 CSVs using first and last names to a third CSV?
How do I query AD using both the first name and last name and add that information to the third CSV? (I don't want to use "get-aduser -filter * | where" because the Domain is huge and so are the CSVs. )
CSV Data is structured Like this
CSV1
CSV2
Wanted output
EDIT
I see what I was doing wrong with querying AD with the multiple filters.
I was trying to use $row.lastname and $row.firstname as my filter instead of setting a variable.
$CSV1 = import-csv .\CSV1.csv
ForEach ($Row in $CSV1){
$ln=$row.LastName
$fn=$row.FirstName
get-aduser -filter {sn -eq $ln -and GivenName -eq $fn} | select UserPrincipalName
}