Solved

Find an object in an array

Posted on 2014-02-26
2
202 Views
Last Modified: 2014-02-26
Hello,

I've a simple object defined like this :

    $myEvent = "" | Select-Object cn, HomeFolder, Documents, AppData, Rights_Home, Rights_AppData, Owner

the script loops many time and in every loop do a : $AllEvents += $myEvent

Now I want to find in $AllEvents a specific cn value to modify attributes

for exemple : $AllEvents[$idx].Documents = "test"

where $idx is the index value of the element I'm looking for

Thx in advance
0
Comment
Question by:Sybux
[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 Comments
 
LVL 40

Accepted Solution

by:
footech earned 500 total points
ID: 39890619
You would just have to parse through the array and look for a match from each element.
$AllEvents | ? { $_.cn -eq "whatever" } | % { $_.Documents = "test" }

Open in new window

0
 
LVL 21

Expert Comment

by:Mazdajai
ID: 39890722
You can use the -match operator if you are familiar with regular expression:

$AllEvents|%{
$_.HomeFolder -match "tom|mary|nacy";
}

Open in new window

0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

"Migrate" an SMTP relay receive connector to a new server using info from an old server.
A brief introduction to what I consider to be the best editor for PowerShell.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
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…

749 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