Solved

How would I spread out the columns in this powershell report

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

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

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

I thought I'd write this up for anyone who has a request to create an anonymous whistle-blower-type submission form created using SharePoint 2010 (this would probably work the same for 2013). It's not 100% fool-proof but it's as close as you can get…
This script can help you clean up your user profile database by comparing profiles to Active Directory users in a particular OU, and removing the profiles that don't match.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

776 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