Solved

Powershell comparison and arrays.

Posted on 2015-02-13
3
107 Views
Last Modified: 2015-02-13
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
Comment
Question by:Xytras1
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 40

Accepted Solution

by:
footech earned 500 total points
ID: 40609143
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
 

Author Closing Comment

by:Xytras1
ID: 40609209
Ya.. Didn't think it was possible. Maybe PS 6.0
0
 
LVL 40

Expert Comment

by:footech
ID: 40609429
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

Free NetCrunch network monitor licenses!

Only on Experts-Exchange: Sign-up for a free-trial and we'll send you your permanent license!

Here is what you get: 30 Nodes | Unlimited Sensors | No Time Restrictions | Absolutely FREE!

Act now. This offer ends July 14, 2017.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Active Directory security has been a hot topic of late, and for good reason. With 90% of the world’s organization using this system to manage access to all parts of their IT infrastructure, knowing how to protect against threats and keep vulnerabil…
Uncontrolled local administrators groups within any organization pose a huge security risk. Because these groups are locally managed it becomes difficult to audit and maintain them.
This tutorial will walk an individual through the process of transferring the five major, necessary Active Directory Roles, commonly referred to as the FSMO roles from a Windows Server 2008 domain controller to a Windows Server 2012 domain controlle…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

691 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question