Solved

Powershell comparison and arrays.

Posted on 2015-02-13
3
103 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Copy-Item -UseTransaction not working 2 37
I'm being stupid with my powershell 2 27
Run powershell against OU 7 76
Configure Windows Server 2012 time server 3 37
This article demonstrates probably the easiest way to configure domain-wide tier isolation within Active Directory. If you do not know tier isolation read https://technet.microsoft.com/en-us/windows-server-docs/security/securing-privileged-access/s…
In previous parts of this Nano Server deployment series, we learned how to create, deploy and configure Nano Server as a Hyper-V host. In this part, we will look for a clustering option. We will create a Hyper-V cluster of 3 Nano Server host nodes w…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

734 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