Solved

Find an object in an array

Posted on 2014-02-26
2
201 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
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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Microsoft Windows Server Update Service (WSUS) is free for everyone, but it lacks of some desirable features like send an e-mail to the administrator with the status of all computers on the WSUS server. This article is based on my PowerShell script …
This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

829 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