Convert text to html format

Welcome Forums General PowerShell Q&A Convert text to html format

This topic contains 2 replies, has 3 voices, and was last updated by

2 years, 7 months ago.

  • Author
  • #48962

    Points: 11
    Rank: Member

    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


  • #48966

    Points: 0
    Rank: Member

    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?

  • #49088

    Points: 1
    Rank: Member

    Would something like this work for you:

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

The topic ‘Convert text to html format’ is closed to new replies.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort