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?
Best Answer
Given the example CSV file "domain1.xxx.org.csv", with contents as:
We can see how
Import-Csv
converts the text into a PSCustomObject using the headings:Filtering this via
Select-Object SAMAccountName
results in the following:If you want to compare the NoteProperty across two PSCustomObjects, because we're not just evaluating a String, you'll just need to tell
Compare-Object
which Property you want to compare with: