I have a table which is created using Time as the Column names. However if the first row does not have data in certain Hours(column) then the column does not show the column for the rest of the table. Thus, I'm trying to create a dynamic select statement which will get every hour since midnight and use these hours as search variables. I have accomplish to get the Select statement created but its not invoking/executing the query.
Any suggestion to get data returned and build the HTML table would be great appreciated.
Code:
$UniversalCurrTime = ((Get-Date).ToUniversalTime()).ToString('h tt')
$UniversalMidnight = ((Get-Date).ToUniversalTime().Date).ToString('h tt')
$hoursBetween = $UniversalMidnight
Write-host 'This is midnight: ' $UniversalMidnight
Write-host 'This is Current time: ' $UniversalTime
$HourSpan = @()
$HourSpan += 'VaultName'
$HourSpan += $UniversalMidnight #($hoursBetween).ToString('h tt')
Do{
$HourSpan += "'" + ($hoursBetween).ToString('h tt') + "'"
$hoursBetween = (Get-date $hoursBetween).AddHours(1)
Write-host 'This is time being added to collection: ' $hoursBetween
}while($hoursBetween -le $UniversalCurrTime)
$HourSpan += 'TotalMessages'
$selectObject = '$reportList |Select-Object ' + (($HourSpan -split '\n') -join ",") + '| ConvertTo-Html -Fragment -ErrorAction SilentlyContinue'
$html = Invoke-Command -ScriptBlock {$selectObject}
Output on the screen but not executed to return data.
$reportList |Select VaultName,'12 AM','1 AM','2 AM','3 AM','4 AM','5 AM','6 AM','7 AM','8 AM', '9 AM','10 AM','11 AM','12 PM','1 PM','2 PM','3 PM','4 PM','5 PM','6 PM','7 PM', '8 PM', '9PM', '10 PM', '11 PM', 'TotalMessages' |Where-Object { -Not [String]::IsNullOrWhiteSpace($_) }| ConvertTo-Html -Fragment -ErrorAction SilentlyContinue
This statement should be executed.