Silentbob
Silentbob

Reputation: 3065

Powershell formatting imported XML as a datatable

I am using Powershell to import an XML file and I would like to format the data as a datatable.

Using the question below I can view the data as a table in the powershell console.

StackOverflow question

The powershell I produced from this question is shown below.

$peakPrices = $dt.heml.Transactions.Record | format-table -AutoSize -Property @{Label="Period";Expression={$_.column[0]."#text"}},
@{label="PeaksBid";Expression={$_.column[9]."#text"}}, @{label="PeaksOffer";Expression={$_.Column[11]."#text"}}, @{label="ReportDate";Expression={$todaysDate}}

This produces a nice view of the data in the form of a table but I dont seem to be able to do what I want with it i.e. loop through each row and do stuff.

The resultant table from the code above looks similar to this.

Picture of table

I would like to change this data to a datatable as I am competent at manipulating these. Is this something I can do?

Upvotes: 1

Views: 1143

Answers (1)

Mathias R. Jessen
Mathias R. Jessen

Reputation: 174445

Format-Table will return pre-formatted data for displaying in the host application. If you want to select calculated properties for further processing use Select-Object instead:

... | Select-Object -Property @{Label="Period";Expression={$_.column[0]."#text"}},@{label="PeaksBid";Expression={$_.column[9]."#text"}}, @{label="PeaksOffer";Expression={$_.Column[11]."#text"}}, @{label="ReportDate";Expression={$todaysDate}}

Upvotes: 1

Related Questions