Solved

Powershell comparison and arrays.

Posted on 2015-02-13
3
91 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
  • 2
3 Comments
 
LVL 39

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 39

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

Join & Write a Comment

This is a PowerShell web interface I use to manage some task as a network administrator. Clicking an action button on the left frame will display a form in the middle frame to input some data in textboxes, process this data in PowerShell and display…
This article will help you understand what HashTables are and how to use them in PowerShell.
This tutorial will walk an individual through the steps necessary to join and promote the first Windows Server 2012 domain controller into an Active Directory environment running on Windows Server 2008. Determine the location of the FSMO roles by lo…
This tutorial will walk an individual through the process of configuring their Windows Server 2012 domain controller to synchronize its time with a trusted, external resource. Use Google, Bing, or other preferred search engine to locate trusted NTP …

757 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now