See if this works for you:
# just sample data -- to be replaced by CSVs
$csvone = @"
EEID,LastName,FirstName
1,Smith,Joe
2,Moore,Steve
3,Blow,Joe
"@
$csvtwo = @"
LastName,FirstName,JobCode
Moore,Steve,101
Smith,Joe,100
Blow,Joe,102
"@
$CSV1 = $csvone | ConvertFrom-Csv # substitute Import-CSV here
$CSV2 = $csvtwo | ConvertFrom-Csv # substitute Import-CSV here
# begin the aggregation
$csv1props = $csv1[0].psobject.properties.name
$final = @{}
# build the initial hash
ForEach ($l in $CSV1){
$key = $l.LastName,$l.FirstName -join "*" # unlikely to find asterisk in names
if ($final.ContainsKey($key)){
Write-Host "Found duplicate in CSV1: $key"
Continue
}
$emp1 = [ordered]@{}
foreach ($p in $csv1props){
$emp1[$p] = $l.$p
}
$final[$key] = $emp1
}
# add the JobCode to the hash based on matching "LastName*FirstName" keys
ForEach ($l in $CSV2){
$key = $l.LastName,$l.FirstName -join "*"
if (-NOT $final.ContainsKey($key)){
Write-Host "Didn't find '$key' from CSV2 in CSV1"
Continue
}
$final[$key]["JobCode"] = $l.JobCode
$u = get-aduser -filter {sn -eq $($l.LastName) -and GivenName -eq $($l.FirstName)}
if (-NOT $u){
Write-Host "Failed to find user '$($l.LastName) $($l.FirstName)' in AD"
$final[$key]["UPN"] = "UNKNOWN"
}
else{
$final[$key]["UPN"] = $u.UserPrincipalName
}
}
$final.keys |
ForEach-Object{
[PSCustomObject]$final.$_
}