Windows Vista Forums

Output to HTML

  1. #1


    Monkey Guest

    Output to HTML

    I have a script that checks a text file for folder paths and then calculates
    the folder sizes and amount of items. I had it originally outputting to CSV
    but wanted to make it output to HTML. I have got it doing this, but it
    doesn't look very tidy. I also wondered if it is possible to have the output
    display red if the number of items are above 10,000. It also seems to take a
    while to run and wondered if anyone could help?

    Get-Content C:\folders.txt `
    | ForEach-Object {
    $stats = Get-ChildItem $_ -Force -Recurse | Measure-Object -Property
    Length -Sum
    New-Object PSObject `
    | Add-Member -MemberType NoteProperty -Name Path -Value $_
    -PassThru `
    | Add-Member -MemberType NoteProperty -Name NumItems -Value
    $stats.Count -PassThru `
    | Add-Member -MemberType NoteProperty -Name Size -Value
    ('{0:0.##} GB' -f ($stats.Sum / 1GB)) -PassThru
    } `
    | ConvertTo-HTML name, path, NumItems, Size -title "Exchange Logs" |
    Set-Content C:\inetpub\wwwroot\PS-exchangelogs.html


      My System SpecsSystem Spec

  2. #2


    Chris Dent Guest

    Re: Output to HTML


    I can't tell you much about the run-speed, it depends a lot on the
    number of folders you're testing and how many items hide in there.

    Anyway, you can do a hell of a lot more with the style than I have here,
    but this would seem like a reasonable start (w3schools.com is a fine
    place to start if you want to learn basic HTML / CSS):


    # A style to insert into the Html Head
    $Head = "
    <title>Exchange Logs</title>
    <style type='text/css'>
    td.Red { color: Red }
    </style>"

    # Generate the base Html
    $Html = Get-Content C:\Folders.txt | %{
    # Get the size and count
    $Stats = Get-ChildItem $_ -Force -Recurse | Measure-Object Length -Sum

    # Construct an object the old-fashioned way
    $_ | Select-Object `
    @{n='Path';e={ $_ }},
    @{n='NumItems';e={ $Stats.Count }},
    @{n='Size';e={ '{0:0.##} GB' -f ($Stats.Sum / 1GB) }}

    } | ConvertTo-Html -Head $Head

    # Match and replace NumItems over 10000
    $Html = $Html | %{
    # Match from the beginning of the line, on the second
    # field (NumItems), and catch digit strings 5 or more long
    If ($_ -Match "^<tr><td>.*</td><td>\d{5}") {
    # Add the class tag for the TD element on this row
    $_ -Replace "<td>", "<td class='Red'>"
    } Else {
    # Otherwise leave the line unmodified
    $_
    }
    }

    # Write all of it back to a file
    $Html > "c:\inetpub\wwwroot\PS-exchangelogs.html"

      My System SpecsSystem Spec

  3. #3


    Chris Dent Guest

    Re: Output to HTML

    Chris Dent wrote:

    >
    > I can't tell you much about the run-speed, it depends a lot on the
    > number of folders you're testing and how many items hide in there.
    >
    > Anyway, you can do a hell of a lot more with the style than I have here,
    > but this would seem like a reasonable start (w3schools.com is a fine
    > place to start if you want to learn basic HTML / CSS):
    >
    > $Snip
    Just to be clear, all you need do to make the output pretty is play with
    the HTML.

    You might extend the style above rather a lot. For example, you might
    set a default font, and you might align to the left, or you might make
    the table fixed size.

    If you want the table contents to be sorted on size / number of items I
    suggest you do that before you convert to HTML

    Here's an extended CSS style example to get you started off:


    # A style to insert into the Html Head
    $Head = "
    <title>Exchange Logs</title>
    <style type='text/css'>
    table { border-collapse: collapse; width: 700px }
    body { font-family: Arial }
    td, th { border-width: 2px; border-style: solid; text-align: left;
    padding: 2px 4px; border-color: black }
    th { background-color: grey }
    td.Red { color: Red }
    </style>"

      My System SpecsSystem Spec

Output to HTML

Similar Threads
Thread Forum
HTML Anchor not jump to the particular Anchor Point in New HTML document
We are working in the Health Archiving HTML CD, we are facing these problem, Experts, please try to give solution to solve this problem. Problem:...
Browsers & Mail
Formating win32_bios output as HTML
I'm starting to experiment with PowerShell, and I'm trying to convert the output of this statement into a HTML page: get-wmiobject win32_bios |...
PowerShell
Enexpected output when using output-csv
when I add the Output-csv my my code, I get different output than what I got on the screen. Here's my code: @( ForEach($user in Get-Content...
PowerShell
working on html objects using HTML DOM, VBscript
Hi All, I have one html page with forms and objects like radiobuttons, checkboxes, dropdown list, text boxes, links..... I will perform some...
VB Script
No output from write-output
I have this script, which does not run as I expected. ---------------------------------------- function foo($bar) { write-output "I got $bar" }...
PowerShell
Formatting HTML output possible?
Hey all, I've found that I'm stuffing too much output on the screen for the built in tables to be able to deal with, so I started using...
PowerShell
Better HTML-ized output to file unicode/ascii thing
I desire simple generic lists of PS objects into html files. So far what I have seems klunkey. I cant seem to get ConvertTo-HTML to cooperate. ...
PowerShell