Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Powershell convert to CSV formatted file

Powershell convert to CSV formatted file

Powershell convert to CSV formatted file

Need help on Powershell

I have file with data like this:

++++++++++++++++Input file +++++++++++++++++++++++++++++
User Name: Power DBA
Role: Power DBA
Last Login Date: Jul 1, 2011 4:54:18 PM

User Name: Power User
Description: Admin Team
Role: Power User
Last Login Date: Mar 15, 2011 8:16:19 AM

User Name: guest
Description: Monitoring
Role: Operator
Last Login Date: Dec 14, 2011 3:45:29 PM


I need to convert this to CSV formatted file using Powershell

+++++++++++++++++++++ file output should like this ++++++++++++++++++
User Name,Description, Role, Last Login Date

Power DBA,, Power DBA, Jul 1, 2011 4:54:18 PM

Power User,Admin Team,Power User, Mar 15, 2011 8:16:19 AM

guest,Monitoring,Operator,Dec 14, 2011 3:45:29 PM




RE: Powershell convert to CSV formatted file

I don't have time to mock it up in full, but you should be able to read in the file (Get-Content), then split it on the blank lines between each group, then split again by line break. Essentially a multi-dimensional array. Then dump to a single array, and Export-Csv to the file.

Do you have your Tek-Tips.com Swag? I've got mine!

Stop by the new Tek-Tips group at LinkedIn.

RE: Powershell convert to CSV formatted file

Not easy in PS.
I had one of those last week with about 50,000 array members. Dumped to Excel, cell b1=a2 then c1=a3, d1-a4 and so on to get the first row reading right.
Copy columns B onwards from row 1 to the end.
Copy and paste the formulae to values.
Sort the whole data cube by column A
Delete all ROWS where column A doesn't start Username.

There's your data in correct forum.
Find and replace column A to replace "Username: " with blank
Repeat for other columns.

Robert is most definitely your Mother's Brother.

RE: Powershell convert to CSV formatted file

What is generating your input file?

I hope that helps.



Check out my scripting solutions at http://www.thespidersparlor.com/vbscript

Work SMARTER not HARDER. The Spider's Parlor's Admin Script Pack is a collection of Administrative scripts designed to make IT Administration easier! Save time, get more work done, get the Admin Script Pack.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close