Array match

Dear all, I need your help with comparing two arrays.

I have two lists:

“Vpn Users”,“XXXXXX”,“XXXXXX”,“CN=XXXXXX,OU=example,DC=mydomain,DC=world,DC=com”
“Vpn Users”,“YYYYYY”,“YYYYYY”,“CN=YYYYYY,OU=example,DC=mydomain,DC=world,DC=com”
“Vpn Users”,“ZZZZZZ”,“ZZZZZZ”,“CN=ZZZZZZ,OU=example,DC=mydomain,DC=world,DC=com”


I need to match all entry in File1 with all entry in File2 and generate output like

User XXXXXX is Employee
User YYYYYY is Consultant
User ZZZZZZ is not present

Could someone please help me kindly?
It would help me a lot.

Thanks in advance.

Please, when you post code or example data you should format this as code using the code tag button named “PRE”. Thanks.

You could use the cmdlet Compare-Object but that would require the data to have at least one common member in each data set. At the moment I cannot see any in your example data. You have in both data sets a column named name but they don’t have any common name in it.

If you want to compare the data based on SAMAccountName from the first data set and Login from the second data set you could do it like this:

$Data1 = @'
"Vpn Users","XXXXXX","XXXXXX","CN=XXXXXX,OU=example,DC=mydomain,DC=world,DC=com"
"Vpn Users","YYYYYY","YYYYYY","CN=YYYYYY,OU=example,DC=mydomain,DC=world,DC=com"
"Vpn Users","ZZZZZZ","ZZZZZZ","CN=ZZZZZZ,OU=example,DC=mydomain,DC=world,DC=com"
'@ |

$Data2 = @'
    ConvertFrom-Csv |
        Select-Object -Property Name,Surname,@{Name = 'sAMAccountName';Expression = {$_.Login}},Type

Compare-Object -ReferenceObject $Data2 -DifferenceObject $Data1 -Property sAMAccountName -PassThru -IncludeEqual |
    Format-Table -AutoSize

Dear Olaf, thank you very much.

Sorry! Next time I’ll use the PRE tag. I promise you :slight_smile:

Your code work perfectly.Thanks
In my code the 2 arrays are populated with Import-csv command.

How can I use your logic using the Import-csv instruction?

Sorry…I’m very ignorant !

Thank you so much Olaf.

You simply import the data into $Data1 and $Data2.


thank you very very very much for your precious help!


Best regards