Sunday, January 1, 2012

Export get-member data to csv file

Each time I was running get-member to get properties or method i was getting huge list, and searching through required property or method or reading definition was a headache in Powershell console.    
If you export all data to CSV it is convenient to make note and preserve your findings, command in CSV files.

************************************************************************
$process = get-process
$properties= $process | get-member
$properties | export-csv -path c:\scripts\test1.csv
************************************************************************

Earlier I was running below script to get data exported to CSV file, but every time I required to format data (Open CSV; copy all contents to notepad, then rename notepad extension .txt to .csv)

************************************************************************
#Open test.csv; copy all contents to notepad, then rename notepad extension .txt to .csv
$process = get-process
$properties= $process | get-member
foreach ($prop in $properties) {$final += “`n” + $prop.name + ", " + $prop.membertype + ", " +  $prop.definition}
$final | out-file c:\scripts\test.csv
************************************************************************

It seems that when I extract data from $properties ($prop) it goes into string format. I am trying to figure it out. Once I get solution I will post it.
Currenlty I am reading Master-PowerShell | With Dr. Tobias Weltner, Free to download as a PDF. It is really a great source to self study.


No comments: