Convert text to html format

Tagged: 

This topic contains 2 replies, has 3 voices, and was last updated by  parjoh01 1 year ago.

  • Author
    Posts
  • #48962

    Venkata Kalyan
    Participant

    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

  • #48966

    Craig Duff
    Participant

    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 1 year ago by  Craig Duff.
  • #49088

    parjoh01
    Participant

    Would something like this work for you:

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

You must be logged in to reply to this topic.