Solved

Microsoft Exchange 2010 PowerShell weirdness

Posted on 2016-09-12
8
43 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
  • 3
  • 3
  • 2
8 Comments
 
LVL 16

Assisted Solution

by:Michael Ortega (Internetwerx, Inc.)
Michael Ortega (Internetwerx, Inc.) 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
ID: 41794122
Interesting. Thanks for the update. I'll see what I can find as well.

MO
0
 
LVL 2

Author Comment

by:fruitloopy
ID: 41801243
Any luck Michael? There's probably some fiddly thing I have to do regarding maths
0
Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

 
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

Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

We are happy to announce a brand new addition to our line of acclaimed email signature management products – CodeTwo Email Signatures for Office 365.
Follow this checklist to learn more about the 15 things you should never include in an email signature from personal quotes, animated gifs and out-of-date marketing content.
In this video we show how to create a User Mailbox in Exchange 2013. We show this process by using the Exchange Admin Center. Log into Exchange Admin Center.: First we need to log into the Exchange Admin Center. Navigate to the Recipients >> Mailb…
In this Micro Video tutorial you will learn the basics about Database Availability Groups and How to configure one using a live Exchange Server Environment. The video tutorial explains the basics of the Exchange server Database Availability grou…

943 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

10 Experts available now in Live!

Get 1:1 Help Now