Solved

Microsoft Exchange 2010 PowerShell weirdness

Posted on 2016-09-12
8
52 Views
Last Modified: 2016-10-13
I have some slight weirdness happening with a PowerShell script which I am trying to run on our Microsoft Exchange 2010 server.
What I am trying to achieve is to just get an easy on the eye list of the top 30 mailbox sizes. If I run the script directly in the Exchange Management Shell it correctly shows the list:
Get-Mailbox -ResultSize Unlimited | Get-MailboxStatistics | Sort-Object TotalItemSize -Descending | Select-Object DisplayName,TotalItemSize -First 30

Open in new window


This is what I get:
Results from Exchange Powershell
When I run the following code to get it looking pretty it works but the list is completely wrong!
$a = "<style>"
$a = $a + "BODY{font-family: Arial; font-size: 10pt;}"
$a = $a + "TABLE{border-width: 1px;border-style: solid;border-color: black;border-collapse: collapse;}"
$a = $a + "TH{border-width: 1px;padding: 0px;border-style: solid;border-color: black;background-color:thistle}"
$a = $a + "TD{border-width: 1px;padding: 0px;border-style: solid;border-color: black;background-color:palegoldenrod}"
$a = $a + "</style>"

$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri http://server.mkdons.local/PowerShell/
Import-PSSession $Session

Get-Mailbox -ResultSize Unlimited | Get-MailboxStatistics | Sort-Object TotalItemSize -Descending | Select-Object DisplayName,TotalItemSize -First 30 | 

ConvertTo-HTML -head $a | Out-File C:\Temp\Test.htm

Open in new window


Here's the pretty one:
Pretty but wrong
Any ideas?
0
Comment
Question by:fruitloopy
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 2
8 Comments
 
LVL 16

Assisted Solution

by:Michael Ortega
Michael Ortega earned 250 total points
ID: 41794045
Odd, it appears to pull the bottom 30, perhaps? All the mailboxes in the "pretty" output are completely different from the list in the powershell output. What happens if you change your "-Frist 30" sort option to "-Last 30". I wonder if it would do the opposite of what's it's doing now.

MO
0
 
LVL 2

Author Comment

by:fruitloopy
ID: 41794083
Tried that and came out completely different. I think I found the cause...when it is converting it to HTML it seems to have no idea how to differentiate between MB & GB, or even KB.
This is the result from removing the -First 30 parameter:
Removing the -First 30 parameter
Now I have to try and work out how to fix it!
1
 
LVL 16

Expert Comment

by:Michael Ortega
ID: 41794122
Interesting. Thanks for the update. I'll see what I can find as well.

MO
0
What, When and Where - Security Threats from Q1

Join Corey Nachreiner, CTO, and Marc Laliberte, Information Security Threat Analyst, on July 26th as they explore their key findings from the first quarter of 2017.

 
LVL 2

Author Comment

by:fruitloopy
ID: 41801243
Any luck Michael? There's probably some fiddly thing I have to do regarding maths
0
 
LVL 49

Expert Comment

by:Akhater
ID: 41801343
that's because totalitemsize is being treated as a string and not as a number, convert it to MB (or GB) it should fix the problem

Get-Mailbox -ResultSize unlimited | Get-MailboxStatistics |  select-object Displayname, @{expression = {$_.TotalItemSize.Value.ToMB()}; label="TotalItemSizeMB"} | sort totalitemsizeMB
0
 
LVL 2

Author Comment

by:fruitloopy
ID: 41801523
Hi Akhater

I just tried that but the TotalItemSizeMB column is empty:
$a = "<style>"
$a = $a + "BODY{font-family: Arial; font-size: 10pt;}"
$a = $a + "TABLE{border-width: 1px;border-style: solid;border-color: black;border-collapse: collapse;}"
$a = $a + "TH{border-width: 1px;padding: 0px;border-style: solid;border-color: black;background-color:thistle}"
$a = $a + "TD{border-width: 1px;padding: 0px;border-style: solid;border-color: black;background-color:palegoldenrod}"
$a = $a + "</style>"

$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri http://mkdons-serv9.mkdons.local/PowerShell/
Import-PSSession $Session

Get-Mailbox -ResultSize unlimited | Get-MailboxStatistics | select-object Displayname, @{expression = {$_.TotalItemSize.Value.ToMB()}; 

label="TotalItemSizeMB"} | sort TotalItemSizeMB | Select-Object DisplayName,TotalItemSizeMB -First 30 | ConvertTo-HTML -Head $a | Out-File C:\Temp

\Mailbox_size.htm

Open in new window

0
 
LVL 49

Expert Comment

by:Akhater
ID: 41801527
I worte it from the top of my head, I will review the syntax later tonight
0
 
LVL 49

Accepted Solution

by:
Akhater earned 250 total points
ID: 41801599
My syntax is correct you added another | Select-Object to it i guess it is to get out only 30 ??

this code is tested working on my environment

$a = "<style>"
$a = $a + "BODY{font-family: Arial; font-size: 10pt;}"
$a = $a + "TABLE{border-width: 1px;border-style: solid;border-color: black;border-collapse: collapse;}"
$a = $a + "TH{border-width: 1px;padding: 0px;border-style: solid;border-color: black;background-color:thistle}"
$a = $a + "TD{border-width: 1px;padding: 0px;border-style: solid;border-color: black;background-color:palegoldenrod}"
$a = $a + "</style>"

$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri http://mkdons-serv9.mkdons.local/PowerShell/
Import-PSSession $Session

$b = Get-Mailbox -ResultSize unlimited | Get-MailboxStatistics | select-object Displayname, @{expression = {$_.TotalItemSize.Value.ToMB()};label="TotalItemSizeMB"} | sort TotalItemSizeMB -Descending | Select-Object -First 30 

$b | ConvertTo-HTML -Head $a | Out-File C:\Temp\Mailbox_size.htm

Open in new window

0

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

A list of top three free exchange EDB viewers that helps the user to extract a mailbox from an unmounted .edb file and get a clear preview of all emails & other items with just a single click on mailboxes.
Previously, on our Nano Server Deployment series, we've created a new nano server image and deployed it on a physical server in part 2. Now we will go through configuration.
The video tutorial explains the basics of the Exchange server Database Availability groups. The components of this video include: 1. Automatic Failover 2. Failover Clustering 3. Active Manager
how to add IIS SMTP to handle application/Scanner relays into office 365.
Suggested Courses

617 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