Author Posts

August 1, 2016 at 4:17 pm

Hi,
I have a text file & trying to convert it to html format. It's working fine, but the data is not coming in tabular format.

Below is the script:

$SourceFile = "C:\temp\kalyan.txt"
$TargetFile = "C:\temp\kalyan.htm"

$File = Get-Content $SourceFile
$FileLine = @()
Foreach ($Line in $File) {
$MyObject = New-Object -TypeName PSObject
Add-Member -InputObject $MyObject -Type NoteProperty -Name Status -Value $Line
$FileLine += $MyObject
}
$FileLine | ConvertTo-Html -Property HealthCheck -body "Running Stausk" | Out-File $TargetFile

Can someone help me on how to get tabular format.

My text file contains below:
ServerName TimeStamp Status
———- ——— ——
Kalyan 2016-08-01T08:01:56 Running

-Kalyan

August 1, 2016 at 4:22 pm

You'd have to write a custom function to turn the inputted text back into powershell objects. I suspect that you are generating the text file with powershell. If that is the case, you can build the html from wherever you got the original data from. So, how is the text file generated?

  • This reply was modified 2 years, 1 month ago by  Craig Duff.

August 2, 2016 at 7:11 pm

Would something like this work for you:

Import-Csv $SourceFile | Select-Object -Property * | ConvertTo-Html -Title "Running Stausk" | Out-File $TargetFile