Link to home
Start Free TrialLog in
Avatar of Carl Billington
Carl BillingtonFlag for Australia

asked on

Find all mailboxes that are under 1024MB

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.
Avatar of Brendan M
Brendan M
Flag of Australia image

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

Avatar of Carl Billington

ASKER

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.
I think line 33 should have $aduser instead of $user

    if ($aduser.MemberOf -notmatch "Mailbox Quota Policy")
Thanks but no results are displaying now.
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

Thanks, but the script is still listing users who are a member of Mailbox Quota Policy security group.
ASKER CERTIFIED SOLUTION
Avatar of Brendan M
Brendan M
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
You're a genius!!!
:) glad to help