Solved

Microsoft Exchange 2010 PowerShell weirdness

Posted on 2016-09-12
8
37 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
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Join & Write a Comment

Disabling the Directory Sync Service Account in Office 365 will stop directory synchronization from working.
Find out how to use Active Directory data for email signature management in Microsoft Exchange and Office 365.
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 video we show how to create an Accepted Domain 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 Mail Flow >> Ac…

705 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

19 Experts available now in Live!

Get 1:1 Help Now