Solved

How would I spread out the columns in this powershell report

Posted on 2009-07-08
4
648 Views
Last Modified: 2012-06-22
Hello All,

Chris-Dent helped me make an HTML report.  The powershell code does exactly what I want it to.  However, the columns are a little too close to eachother.  Where would I put `t within the code to spread things out a bit?  The code is provided below.

$Body = Get-MailboxStatistics -Server mail01 | `
  Where-Object{ $_.storagelimitstatus -eq "issuewarning" } | `
  Sort-object TotalItemSize -descending | `
    Select-Object `
    @{n="User";expression={ $_.DisplayName }}, `
    @{n= "Mailbox Size (MB)";expression={ $_.TotalItemSize.Value.ToMB() }} | `
      ConvertTo-HTML -Title "Mailbox Statistics"
0
Comment
Question by:ndalmolin_13
  • 2
  • 2
4 Comments
 
LVL 70

Accepted Solution

by:
Chris Dent earned 250 total points
ID: 24804739

Hey Nick :)

You could have asked in the other question. Not to worry, it's different enough not to matter.

I think we should apply a Style to our generated HTML. This is a simple example, we add a style statement to the header, and have it set a width of 200px for the columns and align the header titles to the left (I didn't like them centred personally). Anything else you'd like in there? :)

I wondered if you wanted to sort the contents of the output as well. For example, you might add Sort-Object in like this...

$Body = Get-MailboxStatistics | `
  Where-Object{ $_.storagelimitstatus -eq "issuewarning" } | `
  Select-Object `
    @{n="User";e={ $_.DisplayName }}, `
    @{n="Mailbox Size (MB)";e={ $_.TotalItemSize.Value.ToMB() }} | `
  Sort-Object "Mailbox Size (MB)" -Descending | `
  ConvertTo-HTML -Title "Mailbox Statistics" -Head $Header
# The header for the message
 

$Header = "<style type='text/css'>`n" + `

  "td { width: 200px }`n" + `

  "th { text-align: left }`n" + `

  "</style>"
 

# Create an HTML representation of the original object
 

$Body = Get-MailboxStatistics | `

  Where-Object{ $_.storagelimitstatus -eq "issuewarning" } | `

  Select-Object `

    @{n="User";e={ $_.DisplayName }}, `

    @{n="Mailbox Size (MB)";e={ $_.TotalItemSize.Value.ToMB() }} | `

  ConvertTo-HTML -Title "Mailbox Statistics" -Head $Header

Open in new window

0
 
LVL 1

Author Comment

by:ndalmolin_13
ID: 24805718
Thats it.  I was able to figure out the sorting bit.  Can you tell me what the td in line 4 means and the th in line 5?
Thanks for your help.
0
 
LVL 70

Expert Comment

by:Chris Dent
ID: 24806616

TD is Table Data, TH is Table Header, both refer to the HTML tags in the output. The Style is written in CSS, the kind of thing you have to hit places like w3schools.com for (nothing to do with PowerShell itself) :)

`n is just a line-break in case you didn't know and were curious. Pointless except for when people need to read the HTML source.

And you should be able to see the HTML it makes it you just run $Body in the shell on it's own, or if you do this and open the resulting file up in IE / Firefox / random browser.

$Body > "test.htm"

Either way, you should see that it adds the style into the Head portion of the generated HTML. You'd need view source to see that in the browser (or to open the htm file in notepad).

Chris
0
 
LVL 1

Author Closing Comment

by:ndalmolin_13
ID: 31601141
Thanks for the detailed explaination.  I appreciate it.

Nick
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Why would I want to create a function for tracking messages? I am glad you asked. As with most monotonous/routine tasks, human error tends to creep in after doing the same task over and over again. By creating a function, you load the function once…
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now