Thursday, February 27, 2014

Everyday Powershell Returns! - Find exchange mailbox size

Fresh from an ass kicking at the Winter Scripting games we're back with another useful bit of Powershell!

We're building our Exchange 2013 environment now and have a burning need to see what our users mailboxes look like, in terms of the space they consume.

This little script did the trick for us and helped us plan our new information store layout.

Add-PSSnapin *exchange*

$users = Get-ADUser -searchbase "DC=somedomain,DC=com" -Filter * -Properties department

$report = @()
$count = $users.count
$i = 0
foreach ($user in $users)
{
    $i++
    $prog = ($i/$count* 100
    Write-Progress -Activity "Processing..." -percentcomplete $prog -CurrentOperation $user.samaccountname 
    $temp = ""| select Person, mailboxsize, itemcount, Team, Function
    $mailboxstats = Get-MailboxStatistics $user.samaccountname
    $temp.person = $user.samaccountname
    $temp.mailboxsize = $mailboxstats.totalitemsize.value.toMB()
    $temp.itemcount = $mailboxstats.itemcount
    $temp.team = $user.department
    $report += $temp
}
$report

Should be pretty self explanatory. Ask a question in the comments if you'd like clarification of anything. 

No comments:

Post a Comment