Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • 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!

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

LINK TO THIS FORUM!

Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

Partner With Us!

"Best Of Breed" Forums Add Stickiness To Your Site
Partner Button
(Download This Button Today!)

Feedback

"...(I) have been able to get my problems solved from past messages and also new posts that other users have responded to promptly..."

Geography

Where in the world do Tek-Tips members come from?

Powershell convert to CSV formatted file

santhas (TechnicalUser)
23 May 12 23:14
Need help on Powershell

I have file with data like this:

++++++++++++++++Input file +++++++++++++++++++++++++++++
User Name: Power DBA
Description:
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

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=====


Thanks

San
58sniper (MIS)
24 May 12 10:13
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.

Zelandakh (MIS)
24 May 12 17:16
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.
markdmac (MIS)
21 Jun 12 22:31
What is generating your input file?

I hope that helps.

Regards,

Mark

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.

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!

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