Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 352
  • Last Modified:

Powershell get output and merge the data to new CSV

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
Mandy_
Asked:
Mandy_
  • 2
  • 2
1 Solution
 
becraigCommented:
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
 
QlemoC++ DeveloperCommented:
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
 
Mandy_Author Commented:
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
 
QlemoC++ DeveloperCommented:
In that case just remove the -header UserID. That imports the complete CSV, adding two new columns.
0
 
Mandy_Author Commented:
Thank you. That's it.
0

Featured Post

 The Evil-ution of Network Security Threats

What are the hacks that forever changed the security industry? To answer that question, we created an exciting new eBook that takes you on a trip through hacking history. It explores the top hacks from the 80s to 2010s, why they mattered, and how the security industry responded.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now