Compare-Object 2 CSV sheets to output similarities

I’m attempting to build a PS script to check usernames on two different CSV sheets. One has disabled users, the other has licensed, enabled users. I need to find out if any of the licensed, enabled users appear on the disabled users CSV sheet. I’ve gotten thus far:

compare-object (get-content $File1) (get-content $File2) | format-list | Out-File $Location

But I’m not sure how to get this down just right.

You’ll probably have a better time using Import-Csv, rather than Get-Content. That way you wind up with objects and can make use of the -Property parameter of Compare-Object. Since you’re only interested in users that are in both files, you can use the -IncludeEqual and -ExcludeDifferent switches as well. Something along these lines, assuming that “UserName” is a column name in your files:

Compare-Object (Import-Csv $File1) (Import-Csv $File2) -Property UserName -IncludeEqual -ExcludeDifferent

This is exactly what I needed. Thank you!

No problem, happy to help! :slight_smile: