Solved

Find all mailboxes that are under 1024MB

Posted on 2014-10-21
9
182 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
Independent Software Vendors: 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!

 
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

Office 365 Training for IT Pros

Learn how to provision tenants, synchronize on-premise Active Directory, implement Single Sign-On, customize Office deployment, and protect your organization with eDiscovery and DLP policies.  Only from Platform Scholar.

Question has a verified solution.

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

Windows 10 came with  a lot of built in applications, Some organisations leave them there, some will control them using GPO's. This Article is useful for those who do not want to have any applications in their image (example:me).
This article will help to fix the below errors for MS Exchange Server 2013 I. Certificate error "name on the security certificate is invalid or does not match the name of the site" II. Out of Office not working III. Make Internal URLs and Externa…
In this video we show how to create a Contact 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 Recipients >> Contact ta…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…

695 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