Author Posts

November 3, 2014 at 8:42 am

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.

November 3, 2014 at 9:00 am

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

November 3, 2014 at 3:06 pm

This is exactly what I needed. Thank you!

November 3, 2014 at 3:46 pm

No problem, happy to help! 🙂