I am using PnPPowershell to import some CSV files into SharePoint lists and am having trouble with the person columns. I want to compare the emails in several CSV columns to a list of known site users and then use some other techniques with the "unknowns." But first I have to identify the unknowns.
I can use Get-PnPUser
to get all the site (collection) confirmed users and it is an array of object something like this. Currently there are about 720 users in our site.
[PSCustomObject]@{Email=first.mi.last@example.org,
Id=9,
Title=Rothrock}
And then I have the array of object being read from the CSV file. There are about 11,000 of these records and they have many more properties than I've shown here.
[PSCustomObject]@{OwnerEmail=SomePersonOrOther@example.com,
ContactEmail=SomebodyElse@example.com,
Title=Something or other,
ReviewDate=7/25/2022,
...}
I need to compare all of the "email" properties/columns from the CSV to the known users and find the "unknown" people.
I found this page about performing set operations. It uses Compare-Object
and I read the MS documentation, which has a -Property
switch for which object property should be compared. For example if I want to compare the email properties of the objects.
$result = Compare-Object -DifferenceObject $users $inputCSV -Property email
This is working well for me when my object both have a property with the same names. But I want to compare the email property from users with several differently named properties in the CSV. For example compare the User.Email to InputCSV.OwnerEmail and also to InputCSV.ContactEmail and so on.
Is there a way to quickly compare objects with different property names?