hbkrules69
 New Member Posts:2
 |
| 06/28/2008 8:36 AM |
|
Hello,
I am wondering if there is any way to output the mailboxstats of all users on a mail server by either username or Alias. I have been doing it by displayname, which is fine, but when I run the displayname against an A/D query to see which account is disabled/enabled, my output of names is longer than what I originally started with. This is because we always have employees that leave the company as employees and come back as contractors, and they get a new A/D account where the display name is usually the same. Any assistance is very much appreciated
My Code
Get-mailboxserver -id: |get-mailboxstatistics|fl displayname, itemCount
Get-mailboxserver -id: |get-mailboxstatistics|fl , itemCount
This code provides a blank continous column under Alias
Thanks.. |
|
|
|
|
ziembor
 New Member Posts:7
 |
| 06/28/2008 10:08 AM |
|
try
get-Mailbox| get-MailboxStatistics
|
|
|
|
|
khiko
 New Member Posts:6
 |
| 06/29/2008 5:59 PM |
|
yap get-mailboxstatistics works. here is what i used, it also give me the output in MB if you are after the sizes of mailboxes Get-MailboxStatistics | Sort-Object TotalItemSize -Descending | ft DisplayName,StorageLimitStatus,@{label="TotalItemSize(MB)";expression={$_.TotalItemSize.Value.ToMB()}},ItemCount |
|
|
|
|
ckemppel
 New Member Posts:5
 |
| 07/23/2008 6:29 AM |
|
This code worked for what I was looking for as well (thanks!) except I also need to include Alias,Database & SMTP address in the output. When I format as below, the output does include Database, but leaves Alias and SMTP blank Get-MailboxStatistics | Sort-Object TotalItemSize -Descending | ft Alias,Database,*SMTP*,DisplayName,StorageLimitStatus,@{label="TotalItemSize(MB)";expression={$_.TotalItemSize.Value.ToMB()}},ItemCount Any ideas? |
|
|
|
|
marco.shaw Co-Community Director
 Power User Posts:151
 |
| 07/23/2008 6:49 AM |
|
Posted By ckemppel on 07/23/2008 6:29 AM
This code worked for what I was looking for as well (thanks!) except I also need to include Alias,Database & SMTP address in the output. When I format as below, the output does include Database, but leaves Alias and SMTP blank
Get-MailboxStatistics | Sort-Object TotalItemSize -Descending | ft Alias,Database,*SMTP*,DisplayName,StorageLimitStatus,@{label="TotalItemSize(MB)";expression={$_.TotalItemSize.Value.ToMB()}},ItemCount
Any ideas?
get-mailboxstatistics doesn't have any such members:
get-mailboxstatistics|get-member *smtp*,*alias* <--returns nothing |
|
Marco
*Microsoft MVP - Windows PowerShell: http://www.microsoft.com/mvp *PowerGadgets MVP: http://www.powergadgets.com/mvp *Blog: http://marcoshaw.blogspot.com |
|
|
ckemppel
 New Member Posts:5
 |
| 07/23/2008 6:58 AM |
|
Thanks Marco, that explains why the output is blank ;) Get-Mailbox | Format-Table Alias,*SMTP* outputs the alias & SMTP so is there a way to string both commands together to get the desired output I need into a single CSV file? |
|
|
|
|
marco.shaw Co-Community Director
 Power User Posts:151
 |
| 07/23/2008 7:09 AM |
|
Posted By ckemppel on 07/23/2008 6:58 AM
Thanks Marco, that explains why the output is blank ;)
Get-Mailbox | Format-Table Alias,*SMTP* outputs the alias & SMTP so is there a way to string both commands together to get the desired output I need into a single CSV file?
Maybe there's a better way, but this should work:
[PS] >get-mailbox|ft alias,@{l="database";e={$_|get-mailboxstatistics|select database}}
Now, that could make a very long command to add everything you're looking for... |
|
Marco
*Microsoft MVP - Windows PowerShell: http://www.microsoft.com/mvp *PowerGadgets MVP: http://www.powergadgets.com/mvp *Blog: http://marcoshaw.blogspot.com |
|
|
ckemppel
 New Member Posts:5
 |
| 07/23/2008 7:39 AM |
|
| Thanks Marco, I will continue trying varients to see if I can get the desired output. |
|
|
|
|
Shay
 Shell Enthusiast Posts:68

 |
| 07/23/2008 10:20 AM |
|
Piping to select will wrap the database coulmn in array, it shows like:
alias database
------ -------------
user @{...}
Try this:
PS > get-mailbox | ft alias, @{l="database";e={ (get-mailboxstatistics $_).database}} |
|
Shay Levy Windows PowerShell MVP http://blogs.microsoft.co.il/blogs/ScriptFanatic |
|
|
ckemppel
 New Member Posts:5
 |
| 07/23/2008 11:34 AM |
|
I was able to get the output I was desiring with the following:
get-mailbox -Server "MYE2K7SERVERNAME" | ft alias, *SMTP*, @{l="Database";e={ (get-mailboxstatistics $_).database}}, @{l="DisplayName";e={ (get-mailboxstatistics $_).Displayname}}, @{l="StorageLimitStatus";e={ (get-mailboxstatistics $_).StorageLimitStatus}},@{l="ItemCount";e={ (get-mailboxstatistics $_).ItemCount}},@{l="TotalItemSize(MB)";e={ (get-mailboxstatistics $_).TotalItemSize.Value.ToMB()}} >f:\mailbox_exports\E2007Mailboxes.csv
However, I've got a couple of challenges yet to figure out:
1. The output is compressing the longer value columns with ellipses {...} in the output file:
Alias PrimarySmtp Database DisplayNam StorageLim ItemCount TotalItemS
Address e itStatus ize(MB)
----- ----------- -------- ---------- ---------- --------- ----------
LOGONID Allan.Us... SERVERNA... UserN, ... BelowLimit 1202 54
How can I format it to output the complete contents of the field?
2. Is there an easy way to name the export file with a date stamp?
Thanks for everyone's help! |
|
|
|
|
Shay
 Shell Enthusiast Posts:68

 |
| 07/23/2008 1:38 PM |
|
I would go this way:
1. You have to many get-mailboxstatistics calls, you can use one call per user.
2. Use select-object instead of format-table and then pipe to export-csv
3. If you need to export output to csv don't use any format-* at the end of the pipeline, let powershell deserialize the output for you.
$Database = @{n="Database";e={ $stats.database }}
$DisplayName = @{n="DisplayName";e={ $stats.Displayname }}
$StorageLimitStatus = @{n="StorageLimitStatus";e={ $stats.StorageLimitStatus }}
$ItemCount = @{n="ItemCount";e={ $stats.ItemCount }}
$TotalItemSize = @{n="TotalItemSize(MB)";e={ $stats.TotalItemSize.Value.ToMB() }}
get-mailbox -server "MYE2K7SERVERNAME" | foreach {
$stats = get-mailboxstatistics $_
$_ | select alias, *SMTP*,$Database,$DisplayName,$StorageLimitStatus,$ItemCount,$TotalItemSize
} | export-csv f:\mailbox_exports\E2007Mailboxes.csv -nti
|
|
Shay Levy Windows PowerShell MVP http://blogs.microsoft.co.il/blogs/ScriptFanatic |
|
|
ckemppel
 New Member Posts:5
 |
| 07/23/2008 6:41 PM |
|
| Thanks Shay, that did the trick and was much more efficient (although for whatever reason I had to use the full -NoTypeInformation instead of -nti in the syntax). Any thoughts on how to have it save the export w/the current date in the export file name? |
|
|
|
|
Shay
 Shell Enthusiast Posts:68

 |
| 07/23/2008 11:42 PM |
|
Sorry, -nti is available in CTP2, you can use -not in v1. How about embedding the date in the file name: ..."E2007Mailboxes_$(get-date -f MM_dd_yyyy).csv" -not |
|
Shay Levy Windows PowerShell MVP http://blogs.microsoft.co.il/blogs/ScriptFanatic |
|
|
bsonposh
 CLI Addict Posts:363
 |
| 07/24/2008 5:18 AM |
|
| I prefer -NoType. I think it is clearer in intent. |
|
Brandon Shell ---------------- Microsoft Powershell MVP https://mvp.support.microsoft.com/profile/Brandon |
|
|
Shay
 Shell Enthusiast Posts:68

 |
| 07/24/2008 6:27 AM |
|
| No doubt :) |
|
Shay Levy Windows PowerShell MVP http://blogs.microsoft.co.il/blogs/ScriptFanatic |
|
|
hbkrules69
 New Member Posts:2
 |
| 07/24/2008 8:22 AM |
|
| thanks for the responses |
|
|
|
|