none
ConvertTo-Html giving garbage value RRS feed

  • Question

  • Hi,

     I have written a PowerShell  script to find the DPI value of my system. When I am running the script and storing the output in a text file , i am getting the output as expected.

    But when I am converting the output in a html format to display in a web browser i am getting a garbage value.

    I am not able to understand why i am getting that type of output. Kindly help.

    Here is my code snippet:

    #########################################################
    #HTML FORMATTING
    #########################################################
    $a = "<style>"
    $a = $a + "BODY{background-color:peachpuff;}"
    $a = $a + "TABLE{border-width: 1px;border-style: solid;border-color: black;border-collapse: collapse;}"
    $a = $a + "TH{border-width: 1px;padding: 0px;border-style: solid;border-color: black;}"
    $a = $a + "TD{border-width: 1px;padding: 0px;border-style: solid;border-color: black;}"
    $a = $a + "</style>"
    #########################################################################################################################


    ###################################################
    #This script is to check whether DPI is set to 100%
    ###################################################
     $next_line = "`r`n"  
    $format="-------------------------------------------------------------------------------------------------------"
    cd 'HKCU:\Control Panel\Desktop'
    $val = Get-ItemProperty -Path . -Name "LogPixels"
    $res=$val.LogPixels
    $per=(100*$res)/96
    $res= 'DPI is set to ' +$per

    $res|ConvertTo-HTML -head $a | Out-File C:\Scripts\kanka1.htm
    Invoke-Expression C:\Scripts\kanka1.htm


    • Edited by Kanak Verma Tuesday, August 22, 2017 9:16 AM
    • Moved by Bill_Stewart Monday, October 2, 2017 9:45 PM Unanswerable drive-by question
    Tuesday, August 22, 2017 9:09 AM

All replies

  • Hi Kanak,

    would you mind posting the code you are using? It's fairly hard to see just what you are doing without ... well, seeing what you are doing.

    At a vague guess, I'd assume you are using something like Format-Table (ft) or Format-List (fl), but without actually seeing your code, that's a bare-assed guess.

    Cheers,
    Fred


    There's no place like 127.0.0.1

    Tuesday, August 22, 2017 9:16 AM
  • You cannot convert a single value to an HTML output.

    "$style <h1>$res</h1" | Out-File C:\Scripts\kanka1.htm

    This will produce a display


    \_(ツ)_/

    Tuesday, August 22, 2017 1:38 PM
  • Thanks a lot.
    Wednesday, August 23, 2017 3:53 AM