Is there a way to convert tables of text into a PowerShell Object

Question:

There are many tools that output their data in in a table format. One such example is diskpart. Shaving off some extraneous output, you would get something like this.

Another example is netstat, which looks like the following:

I am trying to figure out if there is a fairly repeatable way to convert this type of data into an object, such that the properties of the object are the headers in the first row. I know there are a bunch of ways to do this for the output of individual tools using regex, but I am looking for more of a strategy on how to go about solving this, rather than a one-off solution just for diskpart or netstat.

I was trying to figure out how to use Lee Holmes’ script up on Poshcode called Convert-TextToObject, but wasn’t quite sure where to start.

Answer:

Have you seen this:
http://thepowershellguy.com/blogs/posh/archive/2007/03/24/hey-powershell-guy-how-can-i-parse-a-tab-delimited-file-and-then-save-that-as-a-comma-separated-values-file.aspx
It might be what you are looking for.

Source:

Is there a way to convert tables of text into a PowerShell Object by licensed under CC BY-SA | With most appropriate answer!

Leave a Reply