Pretty new to this. I need to compare a column with usernames from one CSV file, against a column with usernames in another CSV file and output if duplicates exists or remove them.
How they currently look:
$File1:
Firstname,Lastname,Username Peter,Larsen,Larsen.123 Pia,Jensen,Jensen.123 Poul,Hansen,Hansen.123
$File2:
Username Larsen.123 Andersen.123 Jensen.123
What I'm looking for:
Firstname,Lastname,Username,Duplicate Peter,Larsen,Larsen.123,True Pia,Jensen,Jensen.123,True Poul,Hansen,Hansen.123,False
It doesn't necessarily have to be a true/false output, removing all duplicate entries from File1 or similar, would be perfectly fine as well. It's essentially just to compare users in our AD against users in our user database, to see if anyone still have access who shouldn't have.
Edit:
Tried with this so far, found in a similar question in here:
foreach ($user in $File1) {
$MatchAccount = (Compare-Object $File2 $user -Property 'Username' -PassThru).Value
$user = Add-Member -InputObject $user -Type NoteProperty -Name 'Value' -Value $MatchAccount
And just importing and exporting the CSV files before and after, in that order.