Powershell Scripting Issue with CSV file data

DRPing.csv
PingStatus.csv
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.

aikimarkCommented:
I would be helpful if you posted representative samples of the input and output files
0
Carmine BrunoAuthor Commented:
I uploaded and embedded with question  I will Re attach here
DRPing.csv
PingStatus.csv
0
aikimarkCommented:
Sorry.  I missed it.  Usually the attachment links follow the question text.
0
ON-DEMAND: 10 Easy Ways to Lose a Password

Learn about the methods that hackers use to lift real, working credentials from even the most security-savvy employees in this on-demand webinar. We cover the importance of multi-factor authentication and how these solutions can better protect your business!

aikimarkCommented:
append\add it as 7th column
DRPing.csv has these eight columns:
Host,EndUser,Department,Transit,TypeName,SerialStatic,Location,StatusName

Open in new window


I see the Status column and assume the host values are used to join the two tables.  Correct?
0
Carmine BrunoAuthor Commented:
Adding Status and its results to the end of the DRPing.csv as a new column would be sufficient. Thanks.
0
aikimarkCommented:
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.Length
#$ping.Length
$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
            }
         else{ 
            $out | Add-Member -MemberType NoteProperty -Name "status" -Value $ping[$idx].status
            }
         $out
         } | Export-Csv PingWithStatus.csv -NoTypeInformation

Open in new window

0

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 !!!!
0
Carmine BrunoAuthor Commented:
Worked perfectly. Lined up with Host. Nice Job !!!
0
Carmine BrunoAuthor Commented:
Wonderful Powershell Script to Merge and Append CSV using a mutual column as a Joining point.
0
aikimarkCommented:
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).
0
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.