1

I have 2D array $dates with 2 columns and multiple rows for example:

$dates[0][0] = 2016.07.20
$dates[0][1] = 1
$dates[1][0] = 2016.08.19
$dates[1][1] = 6
...

I need to add this array to html output as table. For example I have style of html table:

$a = "<style>"
$a = $a + "TABLE{border-width: 2px;border-style: solid;border-color: black;border-collapse: collapse;}"
$a = $a + "TD{border-width: 1px;padding: 0px;border-style: solid;border-color: black;}"
$a = $a + "</style>"

When i use:

$dates | Select @{expression={$_}}| ConvertTo-HTML -head $a | out-file "C:\Test.htm"

I get this output, where they are in the same column:

<tr><td>2016.07.20 1</td></tr>
<tr><td>2016.08.19 6</td></tr>
<tr><td>2016.08.20 6</td></tr>

I need to have values be in different columns:

<tr><td>2016.07.20</td><td>1</td></tr>
<tr><td>2016.08.19</td><td>6</td></tr>
<tr><td>2016.08.20</td><td>6</td></tr>

Unfortunately I was unable to find examples how to fix that. Please can anyone help? How I can add values in different columns?

4
  • Whats wrong with the top results when googling your question title? Like PowerShell Build a 2D HTML table or Powershell: Display array-members in ConvertTo-HTML Commented Sep 7, 2016 at 13:40
  • What kinds of "columns" do the objects in $dates have? Is it just space-separated strings? Objects from a csv? Commented Sep 7, 2016 at 14:17
  • @MathiasR.Jessen - it is just 2-dimensional array of strings. Commented Sep 7, 2016 at 14:37
  • @wOxxOm in both these examples there are "-Header 'OU',..." or "select ComputerName -ExpandProperty Disks". But my array is pretty simple, no Headers, all items are like that: $dates[0][0] = 2016.07.20 ; $dates[0][1] = 1 ; $dates[1][0] = 2016.08.19 ; $dates[1][1] = 6 ... Commented Sep 7, 2016 at 14:40

1 Answer 1

0

Concatenate the array manually:

'<tr>' + (
    ($dates | %{
        '<td>' + ($_ -join '</td><td>') + '</td>'
    }) -join "</tr>`n<tr>"
) + '</tr>'
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.