Solved

Powershell get output and merge the data to new CSV

Posted on 2014-09-28
5
347 Views
Last Modified: 2014-09-29
Dear experts,

i like to merge the data  to a new CSV and append the result of the following code at the end of the source.csv
(export.csv) - pls see source csv attached-

import-csv c:\export.csv -Delimiter ";" -header UserID| % {
  $_ | Add-Member NoteProperty PrimarySMTP (get-mailbox $_.UserID -ea SilentlyContinue | Select -Expand PrimarySMTPAddress) -PassThru |
       Add-Member NoteProperty OWAPolicy ("WebMail" * (get-CASMailbox $_.UserID -ea SilentlyContinue | select -Expand OwaEnabled)) -passThru
} | export-csv c:\emlreport.csv -nti

Open in new window


Your help would be greatly appreciated
mandy
ee-test.csv
0
Comment
Question by:Mandy_
  • 2
  • 2
5 Comments
 
LVL 29

Expert Comment

by:becraig
ID: 40348883
What version of powershell are you using  ?

If you are using version4 you can use export-csv -append  also be sure to specify your delimiter as ";" when saving.
http://technet.microsoft.com/en-us/library/hh849932.aspx
0
 
LVL 69

Expert Comment

by:Qlemo
ID: 40348981
To append additional info to the end of a CSV does not makes sense. You usually want to add data as a column, not as rows, because you always target for a homogenous CSV structure. If we would take UserID, PrimarySMTP and OWAPolicy and append that, the existing records have one meaning (like UserID, Name, Organizational Unit) and the new one a different (UserID, PrimarySMTP, OWAPolicy) with different data types and everything.
So either we take the full CSV as-is, and add new columns, or find those columns in the CSV already but empty (and then only fill out those).
0
 
LVL 2

Author Comment

by:Mandy_
ID: 40349262
The data should serve to add for comparison. They should be generated with the origin CSV and inserted as 2 new columns such in a way that they coincide with the rows of the existing data.
This should be done in one operation using the above script. All together can be written in a new CSV.

At 100 records (100rows) of the origin CSV might be as the result of the above script, only max. 10 have a value. If they are inserted in the correct row, they can be compare a to generate formulas for further treatments depending of this new values.
The column userid is not required twice. It is only important to make sure that the data matching with existing rows.
0
 
LVL 69

Accepted Solution

by:
Qlemo earned 500 total points
ID: 40349405
In that case just remove the -header UserID. That imports the complete CSV, adding two new columns.
0
 
LVL 2

Author Closing Comment

by:Mandy_
ID: 40349446
Thank you. That's it.
0

Featured Post

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

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

"Migrate" an SMTP relay receive connector to a new server using info from an old server.
Previously, on our Nano Server Deployment series, we've created a new nano server image and deployed it on a physical server in part 2. Now we will go through configuration.
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…

733 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