Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How would I spread out the columns in this powershell report

Posted on 2009-07-08
4
Medium Priority
?
702 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 71

Accepted Solution

by:
Chris Dent earned 1000 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 71

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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

My attempt to use PowerShell and other great resources found online to simplify the deployment of Office 365 ProPlus client components to any workstation that needs it, regardless of existing Office components that may be needing attention.
Transferring FSMO roles is done when an admin wants to split roles between certain Domain Controllers or the Domain Controller holding the Roles has been forcefully demoted using dcpromo / forceremoval
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Loops Section Overview

885 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