Solved

Find an object in an array

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

Accepted Solution

by:
footech earned 500 total points
Comment Utility
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
Comment Utility
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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

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…
In this previous article (https://oddytee.wordpress.com/2016/05/05/provision-new-office-365-user-and-mailbox-from-exchange-hybrid-via-powershell/), we made basic license assignments to users in O365. When I say basic, the method is the simplest way …
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

728 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

11 Experts available now in Live!

Get 1:1 Help Now