I use ConvertTo-HTML to convert a list of objects into a table. The only problem is that I cannot define the order of the columns in that table. I want a specific property (hostname) for all of the objects to be the first column in the table. Is there any way to do this?
Example Code:
function Create-MyObject {
param(
$name
)
$object = New-Object -TypeName PSObject -Property @{
"Name" = $name
"Prop1" = Get-Property1 $name
"Prop2" = Get-Property2 $name
"Prop3" = Get-Property3 $name
}
return $object
}
$myarray = @()
foreach($value in $list)
{
$myarray += Create-MyObject -name $value
}
Add-Content -Value $(ConvertTo-HTML $myarray | Out-String) -Path "C:\Temp\output.html"
Prop3,Prop1,Name,Prop2(it might also be alphabetical, but I don't have the actual code to look at at the moment). I wantNameto be first in the list of columns.