Comparing two specific properties of a CSV using Compare-Object isn't giving the expected results

Posted by MDMarra on Server Fault See other posts from Server Fault or by MDMarra
Published on 2012-11-09T15:01:29Z Indexed on 2012/11/09 23:05 UTC
Read the original article Hit count: 190

Filed under:

I have a list of users from two separate domains. These lists are in CSV format and I only care about the SAMAccountName, which is a field in these CSVs.

The code that I'm working with is currently:

$domain1 = Import-CSV C:\Scripts\Temp\domain1.xxx.org.csv | Select-Object SAMAccountName
$domain2 = Import-CSV C:\Scripts\Temp\domain2.xxx.org.csv | Select-Object SAMAccountName

Compare-Object ($domain1) ($domain2)

This is returning only a handful of results (which aren't accurate) in this format:

@{samaccountname=SomeUser}                                       =>

Obviously, Compare-Object isn't evaluating the objects as strings. How do I make this work?

© Server Fault or respective owner

Related posts about powershell