Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Powershell get output and merge the data to new CSV

Posted on 2014-09-28
5
Medium Priority
?
351 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_
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 71

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 71

Accepted Solution

by:
Qlemo earned 2000 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

Veeam Task Manager for Hyper-V

Task Manager for Hyper-V provides critical information that allows you to monitor Hyper-V performance by displaying real-time views of CPU and memory at the individual VM-level, so you can quickly identify which VMs are using host resources.

Question has a verified solution.

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

A project that enables an administrator to perform actions within a user session context not just at the time of login but any time later on day(s) or week(s) later.
Auditing domain password hashes is a commonly overlooked but critical requirement to ensuring secure passwords practices are followed. Methods exist to extract hashes directly for a live domain however this article describes a process to extract u…
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…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

664 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