1

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?

2
  • 1
    Use Select-Object instead of Format-Table Commented Aug 2, 2017 at 10:26
  • spot on thank you, how I do mark this as answered? Commented Aug 2, 2017 at 10:37

1 Answer 1

1

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}}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.