user1612851
user1612851

Reputation: 1214

ConvertTo-HTML - format object properties?

I am outputing an array of objects in HTML using this:

$arrinfo | Where-Object {$_.Status -eq "Delivered"} | ConvertTo-HTML -    PreContent "<h2><font color=green>Delivered:</font></h2>" -Property Name, Outputfile,     StartTime,EndTime,TotalSeconds -fragment |Out-String 

My question is, can I format things without creating a new object? Specifically, I am looking to format the dates (StartTime,EndTime) in a different format.

I guess I could create another array of objects with the format needed, but am wondering if there is a better way.

Upvotes: 1

Views: 2189

Answers (2)

E.V.I.L.
E.V.I.L.

Reputation: 2166

June Blender explains calculated properties in Name that Property.

Get-ChildItem | Select-Object @{Name = "Attributes"; Expression = {$_.Mode}}, 
    @{Name = "Updated_UTC"; Expression = {$_.LastWriteTime.ToUniversalTime()}}, Name

Upvotes: 1

Shay Levy
Shay Levy

Reputation: 126892

You can use calculated properties:

$arrinfo |
Where-Object {$_.Status -eq "Delivered"} | 
Select-Object Name,Outputfile,@{n='StartTime';e={$_.StartTime.ToString('ddMMyyyy')}},@{n='EndTime';e={$_.EndTime.ToString('ddMMyyyy')}},TotalSeconds |
ConvertTo-HTML -PreContent "<h2><font color=green>Delivered:</font></h2>" -Fragment |
Out-String 

Upvotes: 1

Related Questions