My function builds a representation of a table as a PSCustomObject. It has a title, an array of column headers, and a [System.Collection.Generic.List][string]
of rows:
function Create-ConfluenceTable{
param(
[Parameter(mandatory=$true)][string]$Title,
[Parameter(mandatory=$true)][string[]]$Columns
)
$rows = [System.Collections.Generic.List[string]]::new()
$t = [PSCustomObject]@{
Title = $Title;
Columns = $Columns;
Rows = $rows
}
return $t
}
I then have a pipeline-aware function for adding rows to the table.
function AddRow {
param(
[Parameter(mandatory,ValueFromPipeline)]$ConfluenceTable,
[Parameter(mandatory=$true)][string[]]$RowValues
)
process
{
foreach($rv in $RowValues) {
$ConfluenceTable.Rows.Add($rv)
}
}
}
When I create the table and then try to pass values to it, I can’t get any string variables to correctly resolve. When I run this code…
$bar="https://example.com"
$ct = Create-ConfluenceTable -title "URLs" -Columns {"Type","Url"}
$ct | AddRow -RowValues {"Foo",$bar}
$ct
…my output is:
Title Columns Rows
----- ------- ----
URLs {"Type","Url"} {"Foo",$bar}
What I would like to see is:
Title Columns Rows
----- ------- ----
URLs {"Type","Url"} {"Foo","https://example.com"}