Powershell Scripting Issue with CSV file data

Powershell script to get a column from a CSV and append\add it as 7th column to and existing CSV with 6 existing columns
Specific Get Status Colum from PingStatus.csv and Add it to DRPing.csv. Even if we have to Import both and Export all the objects to a new csv. Whatever works
Carmine BrunoAsked:
Who is Participating?
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.

I would be helpful if you posted representative samples of the input and output files
Carmine BrunoAuthor Commented:
I uploaded and embedded with question  I will Re attach here
Sorry.  I missed it.  Usually the attachment links follow the question text.
Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

append\add it as 7th column
DRPing.csv has these eight columns:

Open in new window

I see the Status column and assume the host values are used to join the two tables.  Correct?
Carmine BrunoAuthor Commented:
Adding Status and its results to the end of the DRPing.csv as a new column would be sufficient. Thanks.
With the 478 records, this performed well.  If your files are huge, then we can explore a more efficient script.  Also, there's a join-object routine, in the public domain, that might be helpful.
$drp = Import-Csv drping.csv  #| sort -Property host
$ping = import-csv pingstatus.csv #| sort -Property host
$drp | % -Process{
         $idx = $ping.host.IndexOf($_.host) 
         $out = $_.psobject.Copy()
         if ($idx -eq -1){
            $out | Add-Member -MemberType NoteProperty -Name "status" -Value "MISSING" #or $null
            $out | Add-Member -MemberType NoteProperty -Name "status" -Value $ping[$idx].status
         } | Export-Csv PingWithStatus.csv -NoTypeInformation

Open in new window

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
Carmine BrunoAuthor Commented:
Will test it Out Thank Yopu so much !!!!
Carmine BrunoAuthor Commented:
Worked perfectly. Lined up with Host. Nice Job !!!
Carmine BrunoAuthor Commented:
Wonderful Powershell Script to Merge and Append CSV using a mutual column as a Joining point.
I was playing with the data and discovered that you have duplicate host values in both the DRPing and the PingStatus files.  This can cause erroneous output, since there isn't a way to differentiate which records should be matched (with absolute certainty).
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

From novice to tech pro — start learning today.