Reputation: 1214
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
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
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