• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 127
  • Last Modified:

Powershell comparison and arrays.

I have array that contains many objects, and I would like to see if they match another array with objects.

$SpecialUsers = Get-ADUser -Filter 'Name -like "Smith"'
$NotSpecialUsers = Get-ADUser -Filter 'Name -like "Joe"'

$ThemUsers = $SpecialUsers | Where-Object {$_ -like $NotSpecialUsers}

Not sure how to write this. Trying to skip Foreach and Compare-Object.
0
Xytras1
Asked:
Xytras1
  • 2
1 Solution
 
footechCommented:
Particularly when you have complex objects (objects with multiple properties) like what is returned by Get-ADUser, the only efficient way you have of comparing is with Compare-Object, and you have to specify which properties of those objects you want to compare in order.  You can't just compare one object to another unless it is a simple object like a string.
0
 
Xytras1Author Commented:
Ya.. Didn't think it was possible. Maybe PS 6.0
0
 
footechCommented:
Can I ask why the "B" grade? I think I gave you a complete answer.  If you need something more you should ask before awarding anything less than an "A", particularly in such a short time period.
0

Featured Post

Making Bulk Changes to Active Directory

Watch this video to see how easy it is to make mass changes to Active Directory from an external text file without using complicated scripts.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now