Solved

Exchange Power Shell

Posted on 2010-08-19
9
845 Views
Last Modified: 2012-08-14
I'm new to Exchange Power Shell, I found this script and would like to know if its possible to run it on several Exchange servers at the same time or do you have to run it on each one of them one at a time. Also, can you modify the script to add the location and username?

[PS] D:\>Get-MailboxServer R04BYNMSGA1 | Get-MailboxStatistics | where {$_.ObjectClass -eq "Mailbox" -and $_.TotalItemSize -gt 512000kb} |         Sort-Object TotalItemSize -Descending | FT @{label="Database";expression={$_.DatabaseName}},@{label="User";expression={$_.DisplayName}},@{label="Total Size (MB)";expression={$_.TotalItemSize.Value.ToKB()}},@{label="Storage Limit";expression={$_.StorageLimitStatus}} -auto
0
Comment
Question by:vhaperbaugub
9 Comments
 
LVL 27

Expert Comment

by:shauncroucher
Comment Utility
Yes, no problem running this on two mailbox servers, open two powershell windows and run side by side. or do one after the other like this:

"server1","server2" | get-mailboxserver | get-mail......

Shaun
0
 
LVL 70

Expert Comment

by:Chris Dent
Comment Utility

You can have pretty much anything you want :)

Location is Office?

Exporting to CSV here, I've never liked the use for Format-Table in that example.

Chris
$Servers = "ExchangeServer1", "ExchangeServer2", "ExchangeServer3", "etc"

$Servers | ForEach-Object {
  Get-MailboxStatistics -Server $_ | 
    Where-Object { $_.ObjectClass -eq "Mailbox" -And $_.TotalItemSize -gr 512Mb }
} | Sort-Object TotalItemSize -Descending |
  Select-Object `
    @{n='Database';e={ $_.DatabaseName }},
    @{n='User';e={ $_.DisplayName }},
    @{n='Total Size (MB)';e={ $_.TotalItemSize.Value.ToMb() }},
    @{n='Storage Limit';e={ $_.StorageLimitStatus }},
    @{n='Username';e={ (Get-User $_.LegacyExchangeDN).SamAccountName }},
    @{n='Office';e={ (Get-User $_.LegacyExchangeDN).Office }} |
  Export-Csv "OutputFile.csv" -NoTypeInformation

Open in new window

0
 
LVL 12

Expert Comment

by:Mahmoud Sabry
Comment Utility
just replace "Get-MailboxServer R04BYNMSGA1"

by

Get-Mailbox

this will give u the results for all mailboxes in the organization

and for the output

use  | FT database, displayname,....... etc all separated by commaa
for example
get-mailbox | get-mailboxstatistics | ft database, displayname,totalitemsize

but first to get relaiable result before running the command, adjust the window dimensions from shell properties

and u can use the command start-transcript c:\usersquota.txt

this will put the result in the specified text file, copy the rusult to Excel file, there u can divide quota in byte by 1024*1024 to translate it to MB
0
 

Author Comment

by:vhaperbaugub
Comment Utility
Chris-Dent - The script you provided won't run in PS, I copied and pasted into PS and got this:

[PS] C:\>$Servers = "r04bynmsga1", "r04bynmsga2"
[PS] C:\>
[PS] C:\>$Servers | ForEach-Object {
>>   Get-MailboxStatistics -Server $_ |
>>     Where-Object { $_.ObjectClass -eq "Mailbox" -And $_.TotalItemSize -gr 512
Mb }
>> } | Sort-Object TotalItemSize -Descending |
>>   Select-Object `
>>     @{n='Database';e={ $_.DatabaseName }},
>>     @{n='User';e={ $_.DisplayName }},
>>     @{n='Total Size (MB)';e={ $_.TotalItemSize.Value.ToMb() }},
>>     @{n='Storage Limit';e={ $_.StorageLimitStatus }},
>>     @{n='Username';e={ (Get-User $_.LegacyExchangeDN).SamAccountName }},
>>     @{n='Office';e={ (Get-User $_.LegacyExchangeDN).Office }} |
>>   Export-Csv "OutputFile.csv" -NoTypeInformation
>>
0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 70

Expert Comment

by:Chris Dent
Comment Utility

There's an error (fixed here), but you need to press return again to finish it off.

Chris
$Servers | ForEach-Object {
  Get-MailboxStatistics -Server $_ | 
    Where-Object { $_.ObjectClass -eq "Mailbox" -And $_.TotalItemSize -gt 512Mb }
} | Sort-Object TotalItemSize -Descending |
  Select-Object `
    @{n='Database';e={ $_.DatabaseName }},
    @{n='User';e={ $_.DisplayName }},
    @{n='Total Size (MB)';e={ $_.TotalItemSize.Value.ToMb() }},
    @{n='Storage Limit';e={ $_.StorageLimitStatus }},
    @{n='Username';e={ (Get-User $_.LegacyExchangeDN).SamAccountName }},
    @{n='Office';e={ (Get-User $_.LegacyExchangeDN).Office }} |
  Export-Csv "OutputFile.csv" -NoTypeInformation

Open in new window

0
 

Author Comment

by:vhaperbaugub
Comment Utility
Does this script run against all the Exchange servers or is their a way to add them to the script?
0
 
LVL 70

Expert Comment

by:Chris Dent
Comment Utility

You'd be better with one of msabry06's changes if you want everything.

In context with the bits to get user information...

Chris
Get-Mailbox |
  Get-MailboxStatistics |
  Where-Object { $_.ObjectClass -eq "Mailbox" -And $_.TotalItemSize -gt 512Mb } |
  Sort-Object TotalItemSize -Descending |
  Select-Object `
    @{n='Database';e={ $_.DatabaseName }},
    @{n='User';e={ $_.DisplayName }},
    @{n='Total Size (MB)';e={ $_.TotalItemSize.Value.ToMb() }},
    @{n='Storage Limit';e={ $_.StorageLimitStatus }},
    @{n='Username';e={ (Get-User $_.LegacyExchangeDN).SamAccountName }},
    @{n='Office';e={ (Get-User $_.LegacyExchangeDN).Office }} |
  Export-Csv "OutputFile.csv" -NoTypeInformation

Open in new window

0
 

Author Comment

by:vhaperbaugub
Comment Utility
Does anyone know of a good site to use for Exchange Power Shell example scripts?
0
 
LVL 70

Accepted Solution

by:
Chris Dent earned 500 total points
Comment Utility

I don't, but if you were to learn the basics of PowerShell you'd be able to make your own with very very few limitations.

http://powershell.com/Mastering-PowerShell.pdf

In the example I pasted above only the CmdLets make it Exchange specific, and Get-Help will tell you all you need to know about those (e.g. Get-Help Get-Mailbox -Full | more).

Chris
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Utilizing an array to gracefully append to a list of EmailAddresses
This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
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…
how to add IIS SMTP to handle application/Scanner relays into office 365.

771 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

12 Experts available now in Live!

Get 1:1 Help Now