Solved

Exchange Power Shell

Posted on 2010-08-19
9
854 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
9 Comments
 
LVL 27

Expert Comment

by:shauncroucher
ID: 33474136
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 71

Expert Comment

by:Chris Dent
ID: 33474158

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
ID: 33474801
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
Office 365 Training for Admins - 7 Day Trial

Learn how to provision tenants, synchronize on-premise Active Directory, implement Single Sign-On, customize Office deployment, and protect your organization with eDiscovery and DLP policies.  Only from Platform Scholar.

 

Author Comment

by:vhaperbaugub
ID: 33475217
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
 
LVL 71

Expert Comment

by:Chris Dent
ID: 33475264

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
ID: 33475417
Does this script run against all the Exchange servers or is their a way to add them to the script?
0
 
LVL 71

Expert Comment

by:Chris Dent
ID: 33476635

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
ID: 33504169
Does anyone know of a good site to use for Exchange Power Shell example scripts?
0
 
LVL 71

Accepted Solution

by:
Chris Dent earned 500 total points
ID: 33504573

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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

A quick Powershell script I wrote to find old program installations and check versions of a specific file across the network.
Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
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…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

707 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