Solved

Powershell comparison and arrays.

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

Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

This article outlines the process to identify and resolve account lockout in an Active Directory environment.
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…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

763 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