Solved

How would I spread out the columns in this powershell report

Posted on 2009-07-08
4
659 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

Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

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.
This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
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…

920 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

16 Experts available now in Live!

Get 1:1 Help Now