Combining two 'lists'

I'm running a script to gain some info from get-aduser and dumping to a bunch of CSVs.
I then collect each of these CSV files into one var, $ImportedData.
Next, I check the items present, because if there was a hiccup for whatever reason, I drop "ERROR" in the data, rather than the user's info.
So I filter $ImportedData | where {$_.displayname -like 'ERROR'}
I want to take that grouping and give it one more try, 90% of them work on a subsequent attempt, so I suspect launching these threads at once is causing a timeout.

So, I will be looping through the $Errors and running another get-aduser against the IDs.
But I then want to replace what's in $ImportedData with what I get from my second attempt, although not everything.
So if right now $ImportedData[46] has
ID         |   displayname         |     'Other Important Info'
123456|  ERROR                     |     'Your wife's birthday is 2/18!'

I want to ONLY replace ERROR with the display name (if it was successfully read).

So, how can I update only the ERROR fields in $ImportedData ?
LVL 67
sirbountyAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

footechCommented:
I was doing something similar earlier today.
Basically you need to import everything, then for each object either pass back the object unchanged or modified.
$ImportedData = $ImportedData | ForEach `
{
    If ( $_.displayname -like 'ERROR' )
    {
        $line = $_
        try {
            Set-ADUser $line.samaccountname -DisplayName "something" -ErrorAction Stop
            $line.DisplayName = "updated"
            $line
        }
        catch {
            $line
        }
    }
    Else
    { $_ }
}

Open in new window

I'm not sure what operation you're putting in the try block, but I think you see the idea.
sirbountyAuthor Commented:
Hey, great minds think alike, eh?  :^)

Figured I'd have to loop again, so there's no way to just loop through the 5 errors, instead of all 36,000 records, eh?
footechCommented:
Actually, you can.  In my case, I was updating a field in a .CSV if an operation was successful.  I didn't really think about it if it's all in memory.  When it is, things are even simpler because you don't have to output the unchanged object.
$ImportedData | where {$_.displayname -like 'ERROR'} | % {
    #do something
    $_.displayname = "updated"
}

Open in new window

If you output $ImportedData you will see the elements have been updated.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
SD-WAN: Making It Work for You

As bandwidth requirements and Internet costs grow, businesses naturally want to manage budgets by reducing reliance on their most expensive connection types. Learn more about how to make SD-WAN work for your business in our on-demand webinar!

sirbountyAuthor Commented:
Makes perfect sense and that's what I was thinking of trying...just didn't think it would work, thus the post. :^)
Thanks sir
footechCommented:
Isn't it nice when PS does most of the work for you?
sirbountyAuthor Commented:
Haha - yeah.  And then EE helps with the leftovers. ;^)
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Powershell

From novice to tech pro — start learning today.