Solved

Microsoft Exchange 2010 PowerShell weirdness

Posted on 2016-09-12
8
46 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
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

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

This article explains in simple steps how to renew expiring Exchange Server Internal Transport Certificate.
A procedure for exporting installed hotfix details of remote computers using powershell
To show how to create a transport rule 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 >> Rules tab.:  To cr…
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

778 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