Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Microsoft Exchange 2010 PowerShell weirdness

Posted on 2016-09-12
8
Medium Priority
?
56 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 1000 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
Are You Ready for GDPR?

With the GDPR deadline set for May 25, 2018, many organizations are ill-prepared due to uncertainty about the criteria for compliance. According to a recent WatchGuard survey, a staggering 37% of respondents don't even know if their organization needs to comply with GDPR. Do you?

 
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 1000 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

Looking for the Wi-Fi vendor that's right for you?

We know how difficult it can be to evaluate Wi-Fi vendors, so we created this helpful Wi-Fi Buyer's Guide to help you find the Wi-Fi vendor that's right for your business! Download the guide and get started on our checklist today!

Question has a verified solution.

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

Want to know how to use Exchange Server Eseutil command? Go through this article as it gives you the know-how.
On September 18, Experts Exchange launched the first installment of the Help Bell, a new feature for Premium Members, Team Accounts, and Qualified Experts. The Help Bell will serve as an additional tool to help teams increase question visibility.
To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

688 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