locked
ConvertTo-HTML - Formating Table Headings RRS feed

  • Question

  • I'm currently working on producing a HTML file which will show users that have not logged on in the last 90 days along with other details about the account.  My script creates an array and then uses $[ArrayName] | ConvertTo-HTML to create the HTML page.  Is there a way of changing the headings of the Array to include spaces? for instance 'UserLastLogon' to 'User Last Logon' this would help with the column widths and be a bit easier to read.  Also is there a way of changing the font type/size of the table text, column heading text and -head text?

    My current code is:

    '<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">' | Out-File C:\ScriptResults\LastLogon.htm
    $ResultsArrayTwo | ConvertTo-HTML -head $a -body "<H2>CODE TWO Last AD Logon and Exchange Logon greater than 90 days</H2>" | Out-File C:\ScriptResults\LastLogon.htm -Append

    I then append additional arrays in the same manner with various headings to the same HTML file.

    Thanks.

    Pete.

    Monday, May 16, 2016 11:40 AM

Answers

  • n array does not have headings.

    You can use a stylesheet to adjust column padding.

    To learn how to write HTML/CSS you can look here: http://www.w3schools.com/css/default.asp

    Also:

    $css = 'https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css'
    $pre = '<H2>CODE TWO Last AD Logon and Exchange Logon greater than 90 days</H2>'
    $ResultsArrayTwo | 
    	ConvertTo-HTML -head $a -Pre $pre -CssUri $css | 
    	Out-File C:\ScriptResults\LastLogon.htm
    


    \_(ツ)_/

    • Marked as answer by PeteL1 Monday, May 16, 2016 2:10 PM
    Monday, May 16, 2016 12:19 PM
  • A has is a dictionary of unique name=value pairs.

    You can have:

    @{
         Make='Ford'
         Model='Mustang'
         Color='Black'
    }

    That is a hash.

    This is an object:

    $car=[pscustomobject]@{
         Make='Ford'
         Model='Mustang'
         Color='Black'
    }

    This is an array of objects:

    $cars=@()
    $cars+=$car


    \_(ツ)_/


    • Edited by jrv Monday, May 16, 2016 3:29 PM
    • Marked as answer by PeteL1 Wednesday, May 18, 2016 4:58 PM
    Monday, May 16, 2016 3:28 PM

All replies

  • n array does not have headings.

    You can use a stylesheet to adjust column padding.

    To learn how to write HTML/CSS you can look here: http://www.w3schools.com/css/default.asp

    Also:

    $css = 'https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css'
    $pre = '<H2>CODE TWO Last AD Logon and Exchange Logon greater than 90 days</H2>'
    $ResultsArrayTwo | 
    	ConvertTo-HTML -head $a -Pre $pre -CssUri $css | 
    	Out-File C:\ScriptResults\LastLogon.htm
    


    \_(ツ)_/

    • Marked as answer by PeteL1 Monday, May 16, 2016 2:10 PM
    Monday, May 16, 2016 12:19 PM
  • Hi JRV, thanks for the response.  When you mentioned that the array doesn't have column headings I went back to my code and tried putting quotes around the 'heading' (not quite sure what term to use if these don't become the array headings) values, which worked! Only tried the first value at this stage.

    $ResultsArrayTWO += New-object PSObject -Property([ordered]@{"Account Name" = $AccountName ; Description = $Description ; LastLogonDate = $LastLogonDate ; AccountCreated = $AccountCreated ; PasswordChanged = $PasswordChanged ;PasswordNeverExpires = $PasswordNeverExpires ; HasMailbox = $HasMailBox ;LastMailboxLogonDate = $ExchangeChecks[1] ;ExchLoggedOnBy = $ExchangeChecks[2] ; Investigate = $ExchangeChecks[4]; Why = $ExchangeChecks[5]; ExchLogonDays = $ExchangeChecks[3]})

    Beginners error :-)

    Thanks again.

    Pete.

    Monday, May 16, 2016 2:10 PM
  • Sorry.  I couldn't understand you question because you posted too much sundry information.

    The question should have been.  How do I create a hash where the names have spaces. 

    If you looked it up with help you would see the answer.  Always check help first.

    help about_hash_tables

     Creating Hash Tables
        To create a hash table, follow these guidelines:

             - Begin the hash table with an at sign (@).

             - Enclose the hash table in braces ({}).

             - Enter one or more key/value pairs for the content of the hash
               table.

             - Use an equal sign (=) to separate each key from its value.

             - Use a semicolon (;) or a line break to separate the
               key/value pairs.

             - Key that contains spaces must be enclosed in quotation marks.
               Values must be valid Windows PowerShell expressions. Strings
               must appear in quotation marks, even if they do not include
               spaces.


    \_(ツ)_/


    • Edited by jrv Monday, May 16, 2016 2:36 PM
    Monday, May 16, 2016 2:36 PM
  • Hi JRV

    To be honest I read about Arrays and Hash tables and wasn't sure which one I should be using.  I thought I was using an array and trying to change the column headings.  It seems this may have now changed to a Hash table, although I'm not sure how or indeed if it has.

    When reading information about arrays and hash tables the examples I find seem to use one or two values per 'record', it would be useful if the examples had three values so it is clearer how the specific values are queried for, added to or modified and how all the records are returned. For example:

    Ford, Mustang, Black

    Renault, Clio, Red

    What would be the benefit of using either an array or a hash table for this sort of information.  Are there key deciding factors that mean you should use one or the other.

    What's the difference in how I would change the colour of the Renault if the data was in an array or in a hash table.  How would I sort based on colour of vehicle, while ensuring that colour is the third column in any output.

    Any useful information or links appreciated.

    Regards,

    Pete.

    • Edited by PeteL1 Monday, May 16, 2016 3:21 PM changed wording para 2
    Monday, May 16, 2016 3:19 PM
  • A has is a dictionary of unique name=value pairs.

    You can have:

    @{
         Make='Ford'
         Model='Mustang'
         Color='Black'
    }

    That is a hash.

    This is an object:

    $car=[pscustomobject]@{
         Make='Ford'
         Model='Mustang'
         Color='Black'
    }

    This is an array of objects:

    $cars=@()
    $cars+=$car


    \_(ツ)_/


    • Edited by jrv Monday, May 16, 2016 3:29 PM
    • Marked as answer by PeteL1 Wednesday, May 18, 2016 4:58 PM
    Monday, May 16, 2016 3:28 PM