Solved

Find all mailboxes that are under 1024MB

Posted on 2014-10-21
9
180 Views
Last Modified: 2014-10-23
I would like to find all mailboxes in our Exchange 2010 environment that are under 1024MB who are NOT a member of the security group; 'Mailbox Quota Policy'.
 
Thank you.
0
Comment
Question by:the_omnific
[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
  • 4
  • 3
  • 2
9 Comments
 
LVL 14

Expert Comment

by:brendanmeyer
ID: 40396164
please try out  save as a ps1 file

change line 33 to your group name

$2007snapin = Get-PSSnapin -Name Microsoft.Exchange.Management.PowerShell.Admin
if ($2007snapin)
{
	$AdminSessionADSettings.ViewEntireForest = 1
}
else
{
	$2010snapin = Get-PSSnapin -Name Microsoft.Exchange.Management.PowerShell.E2010
	if ($2010snapin)
	{
		Set-ADServerSettings -ViewEntireForest $true
	}
}
Import-Module ActiveDirectory

$report = @()
Write-Host -ForegroundColor White "Collecting mailbox list"
$mailboxes = @(Get-Mailbox -resultsize unlimited -IgnoreDefaultScope)

Write-Host -ForegroundColor White "Collecting report data"

$mailboxcount = $mailboxes.count
$i = 0

#Loop through mailbox list and find the aged mailboxes
foreach ($mb in $mailboxes)
{
	$i = $i + 1
	$pct = $i/$mailboxcount * 100
	Write-Progress -Activity "Collecting mailbox details" -Status "Processing mailbox $i of $mailboxcount - $mb" -PercentComplete $pct

    $aduser = Get-ADUser $mb.samaccountname -Properties Enabled,AccountExpirationDate
    if ($user.MemberOf -notmatch "Customer Service")
    {
        $tempstat = $mb | Get-MailboxStatistics
        if ($tempstat.TotalItemSize -lt 1024mb)
        {
            $userObj = New-Object PSObject
	        $userObj | Add-Member NoteProperty -Name "DisplayName" -Value $tempstat.DisplayName
	        $userObj | Add-Member NoteProperty -Name "TotalItemSize" -Value $tempstat.TotalItemSize
            $report = $report += $userObj
        }
    }
}

$report | Sort-Object TotalItemSize

Open in new window

0
 
LVL 1

Author Comment

by:the_omnific
ID: 40396184
Thanks. The script is not working. It is still reports users who are a member of the AD security group 'Mailbox Quota Policy'. I have changed change line 33 to my group name.
0
 
LVL 16

Expert Comment

by:Joshua Grantom
ID: 40396921
I think line 33 should have $aduser instead of $user

    if ($aduser.MemberOf -notmatch "Mailbox Quota Policy")
0
Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

 
LVL 1

Author Comment

by:the_omnific
ID: 40398167
Thanks but no results are displaying now.
0
 
LVL 16

Expert Comment

by:Joshua Grantom
ID: 40399408
Try this one. I am going through the script but I do not have exchange so I cannot test, it seems everything was there but I think some changes needed to be made. Let me know
$2007snapin = Get-PSSnapin -Name Microsoft.Exchange.Management.PowerShell.Admin
if ($2007snapin)
{
	$AdminSessionADSettings.ViewEntireForest = 1
}
else
{
	$2010snapin = Get-PSSnapin -Name Microsoft.Exchange.Management.PowerShell.E2010
	if ($2010snapin)
	{
		Set-ADServerSettings -ViewEntireForest $true
	}
}
Import-Module ActiveDirectory

$report = @()
Write-Host -ForegroundColor White "Collecting mailbox list"
$mailboxes = @(Get-Mailbox -resultsize unlimited -IgnoreDefaultScope)

Write-Host -ForegroundColor White "Collecting report data"

$mailboxcount = $mailboxes.count
$i = 0

#Loop through mailbox list and find the aged mailboxes
foreach ($mb in $mailboxes)
{
	$i = $i + 1
	$pct = $i/$mailboxcount * 100
	Write-Progress -Activity "Collecting mailbox details" -Status "Processing mailbox $i of $mailboxcount - $mb" -PercentComplete $pct

    $aduser = Get-ADUser $mb.samaccountname -Properties Enabled,AccountExpirationDate,memberof
    if ($aduser.MemberOf -notmatch "Mailbox Quota Policy")
    {
        $tempstat = $mb | Get-MailboxStatistics
        if ($tempstat.TotalItemSize -lt 1024mb)
        {
            $userObj = New-Object PSObject
	        $userObj | Add-Member NoteProperty -Name "DisplayName" -Value $tempstat.DisplayName
	        $userObj | Add-Member NoteProperty -Name "TotalItemSize" -Value $tempstat.TotalItemSize
            $report = $report += $userObj
        }
    }
}

$report | Sort-Object TotalItemSize

Open in new window

0
 
LVL 1

Author Comment

by:the_omnific
ID: 40400719
Thanks, but the script is still listing users who are a member of Mailbox Quota Policy security group.
0
 
LVL 14

Accepted Solution

by:
brendanmeyer earned 500 total points
ID: 40400800
sorry, been quite busy the last few days

group name is now on line 16

$2007snapin = Get-PSSnapin -Name Microsoft.Exchange.Management.PowerShell.Admin
if ($2007snapin)
{
	$AdminSessionADSettings.ViewEntireForest = 1
}
else
{
	$2010snapin = Get-PSSnapin -Name Microsoft.Exchange.Management.PowerShell.E2010
	if ($2010snapin)
	{
		Set-ADServerSettings -ViewEntireForest $true
	}
}
Import-Module ActiveDirectory

$dn = (Get-ADGroup "Mailbox Quota Policy").distinguishedname # Mailbox Quota Policy

$report = @()
Write-Host -ForegroundColor White "Collecting mailbox list"
$mailboxes = @(Get-Mailbox -resultsize unlimited -IgnoreDefaultScope)

Write-Host -ForegroundColor White "Collecting report data"

$mailboxcount = $mailboxes.count
$i = 0

#Loop through mailbox list and find the aged mailboxes
foreach ($mb in $mailboxes)
{
	$i = $i + 1
	$pct = $i/$mailboxcount * 100
	Write-Progress -Activity "Collecting mailbox details" -Status "Processing mailbox $i of $mailboxcount - $mb" -PercentComplete $pct

    $aduser = Get-ADUser $mb.samaccountname -Properties Enabled,AccountExpirationDate,MemberOf
    if ($aduser.MemberOf.Contains($dn) -eq $false)
    {
        $tempstat = $mb | Get-MailboxStatistics
        if ($tempstat.TotalItemSize -lt 1024mb)
        {
            $userObj = New-Object PSObject
	        $userObj | Add-Member NoteProperty -Name "DisplayName" -Value $tempstat.DisplayName
	        $userObj | Add-Member NoteProperty -Name "TotalItemSize" -Value $tempstat.TotalItemSize
            $report = $report += $userObj
        }
    }
}

$report | Sort-Object TotalItemSize

Open in new window


you can test these two lines in powershell to make sure that the group information loads correctly (with no errors)
Import-Module ActiveDirectory

$dn = (Get-ADGroup "Mailbox Quota Policy").distinguishedname

Open in new window

0
 
LVL 1

Author Closing Comment

by:the_omnific
ID: 40400819
You're a genius!!!
0
 
LVL 14

Expert Comment

by:brendanmeyer
ID: 40400833
:) glad to help
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This script can help you clean up your user profile database by comparing profiles to Active Directory users in a particular OU, and removing the profiles that don't match.
A list of top three free exchange EDB viewers that helps the user to extract a mailbox from an unmounted .edb file and get a clear preview of all emails & other items with just a single click on mailboxes.
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…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

733 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