Find an object in an array

Sybux
Sybux used Ask the Experts™
on
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
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2014
Commented:
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

You can use the -match operator if you are familiar with regular expression:

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

Open in new window

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial