Wrote this script to combine info from two CSVs into one CSV, however, I noticed that if there is not a match in the if statement, then no record is written. How do I get it to write a record even though there is no match for: if ($hr.'Last Name' -eq $user.'Last Name' -And $hr.'First Name' -eq $user.'First Name' )
In other words, if there is not a match, I would like it to write the original record from the combined.csv file.
$hrUsers = Import-Csv -Path "C:\temp\HR.csv"
$combinedUsers = Import-Csv "C:\temp\combined.csv"
foreach ($user in $combinedUsers){
$matched = $false
foreach ($hr in $hrUsers){
$obj = "" | select "First Name","Last Name","Enrollment Date","Due Date","Status","Email Address","Manager", "Company"
if ($hr.'Last Name' -eq $user.'Last Name' -And $hr.'First Name' -eq $user.'First Name' ) {
$matched = $true
$obj.'First Name' = $user.'First Name'
$obj.'Last Name' = $user.'Last Name'
$obj.'Enrollment Date' = $user.'Enrollment Date'
$obj.'Due Date' = $user.'Due Date'
$obj.'Status' = $user.'Status'
$obj.'Email Address' = $user.'Email Address'
$obj.'Manager' = $user.'Manager'
$obj.'Company' = $hr.'Company'
$obj | Export-Csv -Path "C:\temp\experiment2.csv" -Append -NoTypeInformation
}
}
}