Solved

Powershell get output and merge the data to new CSV

Posted on 2014-09-28
5
342 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 28

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 68

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 68

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

The article will show you how you can maintain a simple logfile of all Startup and Shutdown events on Windows servers and desktops with PowerShell. The script can be easily adapted into doing more like gracefully silencing/updating your monitoring s…
I thought I'd write this up for anyone who has a request to create an anonymous whistle-blower-type submission form created using SharePoint 2010 (this would probably work the same for 2013). It's not 100% fool-proof but it's as close as you can get…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

705 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now