Solved

Find an object in an array

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

Comparison of Amazon Drive, Google Drive, OneDrive

What is Best for Backup: Amazon Drive, Google Drive or MS OneDrive? In this free whitepaper we look at their performance, pricing, and platform availability to help you decide which cloud drive is right for your situation. Download and read the results of our testing for free!

Question has a verified solution.

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

This script can help you clean up your user profile database by comparing profiles to Active Directory users in a particular OU, and removing the profiles that don't match.
The following article is intended as a guide to using PowerShell as a more versatile and reliable form of application detection in SCCM.
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…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

696 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