I am looking to setup a powershell script that will append a new line of data to an HTML table on an output file until it is terminated by the user. This particular example is being written to write the current hard disk used space along with a time stamp every two seconds to an HTML file.
I tried using a CSV file for the output, but the script can't write to the CSV file and have it open at the same time. This is important.
$Header = @"
<style>
TABLE {border-width: 1px; border-style: solid; border-color: gray; border-collapse: collapse;}
TH {border-width: 1px; padding: 3px; border-style: solid; border-color: black; background-color: #E1DEDC;}
TD {border-width: 1px; padding: 3px; border-style: solid; border-color: gray;}
</style>
"@
$DateTime = Get-Date -Format G
$FreeDiskSpace = Get-WmiObject -Class Win32_logicaldisk -Filter "DriveType ='3'" | Select -ExpandProperty FreeSpace
Write-Output $Table1| ConvertTo-Html -Head $Header | Out-File -FilePath C:\users\public\documents\FreeSpaceTimeStamp.html
while ($True)
{
$Table1 = new-object psobject
$Table1 | add-member noteproperty Date/Time $DateTime
$Table1 | add-member noteproperty FreeSpace $FreeDiskSpace
Start-Sleep -Seconds 2
}
Right now, the code doesn't keep adding lines to the same HTML file but simply hangs in the while loop and I don't understand why.
Any help is appreciated.
Thanks,
Seth