Solved

Exchange Power Shell

Posted on 2010-08-19
9
850 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
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 70

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
Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

 

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 70

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 70

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 70

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

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.

Question has a verified solution.

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

Suggested Solutions

Learn to move / copy / export exchange contacts to iPhone without using any software. Also see the issues in configuration of exchange with iPhone to migrate contacts.
Read this checklist to learn more about the 15 things you should never include in an email signature.
In this video we show how to create a Resource Mailbox in Exchange 2013. We show this process by using the Exchange Admin Center. Log into Exchange Admin Center.: Navigate to the Recipients >> Resources tab.: "Recipients" is our default selection …
how to add IIS SMTP to handle application/Scanner relays into office 365.

840 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