Solved

Find all mailboxes that are under 1024MB

Posted on 2014-10-21
9
166 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
  • 4
  • 3
  • 2
9 Comments
 
LVL 14

Expert Comment

by:brendanmeyer
Comment Utility
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
Comment Utility
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
Comment Utility
I think line 33 should have $aduser instead of $user

    if ($aduser.MemberOf -notmatch "Mailbox Quota Policy")
0
 
LVL 1

Author Comment

by:the_omnific
Comment Utility
Thanks but no results are displaying now.
0
Too many email signature changes to deal with?

Are you constantly being asked to update your organization's email signatures? Do they take up too much of your time? Wouldn't you love to be able to manage all signatures from one central location, easily design them and deploy them quickly to users. Well, you can!

 
LVL 16

Expert Comment

by:Joshua Grantom
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
You're a genius!!!
0
 
LVL 14

Expert Comment

by:brendanmeyer
Comment Utility
:) glad to help
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Exchange server is not supported in any cloud-hosted platform (other than Azure with Azure Premium Storage).
A procedure for exporting installed hotfix details of remote computers using powershell
In this video we show how to create a mailbox database 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 Servers >> Data…
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…

772 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