Link to home
Start Free TrialLog in
Avatar of Mandy_
Mandy_

asked on

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
Avatar of becraig
becraig
Flag of United States of America image

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
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).
Avatar of Mandy_
Mandy_

ASKER

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.
ASKER CERTIFIED SOLUTION
Avatar of Qlemo
Qlemo
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Mandy_

ASKER

Thank you. That's it.