Solved

Find all mailboxes that are under 1024MB

Posted on 2014-10-21
9
176 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
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
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 
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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

A procedure for exporting installed hotfix details of remote computers using powershell
This article explains how to install and use the NTBackup utility that comes with Windows Server.
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 …
In this Micro Video tutorial you will learn the basics about Database Availability Groups and How to configure one using a live Exchange Server Environment. The video tutorial explains the basics of the Exchange server Database Availability grou…

861 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