Try this (just replace the file path):

 

Get-Content -Path MyFile.txt | ? { $_ -notmatch '--|(Name\s+Value)' } | % {
[void]($_ -match '(\w+)\s+([\w\- ]+)$'); Write-Host -Object ('{0},{1}' -f
$matches[1], $matches[2]); }; 

 

Here's the output I get:

 

Model,25184HU


 


                    

Cores,4


 


                    

RAM,2


 


                  

Vendor,LENOVO


 


                     

Manufacturer,LENOVO


 


                           

Sockets,1


 


                      

CSModelType,ThinkPad T410


 


                          

IdentifyingNumber,R88TGZ7


 


                                

Hostname, 

SystemType,X86-based PC  

 

Cheers,

Trevor Sullivan

 

From: [email protected] [mailto:[email protected]]
On Behalf Of [email protected]
Sent: Wednesday, September 18, 2013 11:22 AM
To: [email protected]
Subject: [powershell] convert text to a csv

 

I have a file with many entries like the below, trying to convert them into
a csv, my googling is failing me today.

 

 

Name                           Value


----                           -----


Model                          25184HU


Cores                          4


RAM                            2


Vendor                         LENOVO


Manufacturer                   LENOVO


Sockets                        1


CSModelType                    ThinkPad T410


IdentifyingNumber              R88TGZ7


Hostname


SystemType                     X86-based PC  

 

Christopher Catlett

Consultant | Detroit



 

Sogeti USA

Office 248-876-9738 |Fax 877.406.9647 

26957 Northwestern Highway, Suite 130, Southfield, MI 48033-8456

 <http://www.us.sogeti.com/> www.us.sogeti.com

 


================================================
Did you know you can also post and find answers on PowerShell in the forums?
http://www.myitforum.com/forums/default.asp?catApp=1 



================================================
Did you know you can also post and find answers on PowerShell in the forums?
http://www.myitforum.com/forums/default.asp?catApp=1

<<image001.jpg>>

Reply via email to