Mailbox Size Restrictions Powershell issue

I recently created, alongside help from others, a powershell script to give us info on the quotas on Exchange 2010 mailboxes.

It works great aside from one thing, when showing the results the users who don't have their quotas customized are showing up as unlimited.

If i were sending this out, the viewer would be confused because it looks as though everyone aside from the customized users have unlimited quotas.

This is not true because they are still using the Default Quota assigned to the database.

Here is the script below, can anyone help us remedy this?

$AllMailboxes = @()
$Mailboxes = Get-Mailbox -ResultSize unlimited | Sort-Object DisplayName | Select DisplayName, IssueWarningQuota, ProhibitSendQuota, ProhibitSendReceiveQuota, Alias
foreach ($Mailbox in $Mailboxes){
    $MailboxStats = "" |Select  DisplayName,IssueWarningQuota,ProhibitSendQuota,ProhibitSendReceiveQuota,TotalItemSize,ItemCount
    $Stats = Get-MailboxStatistics -Identity $Mailbox.Alias
    $MailboxStats.DisplayName = $Mailbox.DisplayName
    $MailboxStats.IssueWarningQuota = $Mailbox.IssueWarningQuota
    $MailboxStats.ProhibitSendQuota =$Mailbox.ProhibitSendQuota
    $MailboxStats.ProhibitSendReceiveQuota =$Mailbox.ProhibitSendReceiveQuota
    $MailboxStats.TotalItemSize = $Stats.TotalItemSize
    $MailboxStats.ItemCount = $Stats.ItemCount
    $AllMailboxes += $MailboxStats
}

$AllMailboxes | Export-Csv C:\scripts\mailboxsizerestrictions.csv -NoTypeInformation
MailboxRestriction.txt
NetGenITAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Dan McFaddenSystems EngineerCommented:
To solve the issue of the users with default or inherited quotas, you will need to also get the "Database" property on the user.

So I would do this:
1. grab the list of mailbox databases and their associated quotas
2. grab the list of mailboxes with the database property included
3. if the quota info returns unlimited, get the default quota info based on the database name of the user's mailbox.

to get & store the database info into an array:

$arrMbDbs = New-object -typeName System.Collections.ArrayList
$arrMbDbs = Get-MailboxDatabase | select Name,IssueWarningQuota,ProhibitSendQuota,ProhibitSendReceiveQuota

Open in new window


Then you could check if the quotas are "unlimited."  If you find an unlimited item, grab the appropriate info from $arrMbDbs:

$MailboxStats.IssueWarningQuota = $arrMbDbs | where {$_.Name -eq $Mailbox.Database} | foreach {$_.IssueWarningQuota}
$MailboxStats.ProhibitSendQuota  = $arrMbDbs | where {$_.Name -eq $Mailbox.Database} | foreach {$_.ProhibitSendQuota}
$MailboxStats.ProhibitSendReceiveQuota  = $arrMbDbs | where {$_.Name -eq $Mailbox.Database} | foreach {$_.ProhibitSendReceiveQuota}

Open in new window


Your script would look like this:

$arrMbDbs = New-object -typeName System.Collections.ArrayList
$arrMbDbs = Get-MailboxDatabase | select Name,IssueWarningQuota,ProhibitSendQuota,ProhibitSendReceiveQuota

$AllMailboxes = @()
$Mailboxes = Get-Mailbox  -ResultSize unlimited  | Select DisplayName, Database, IssueWarningQuota, ProhibitSendQuota, ProhibitSendReceiveQuota, Alias | Sort DisplayName
foreach ($Mailbox in $Mailboxes)
{
    $MailboxStats = "" |Select  DisplayName,IssueWarningQuota,ProhibitSendQuota,ProhibitSendReceiveQuota,TotalItemSize,ItemCount
    $Stats = Get-MailboxStatistics -Identity $Mailbox.Alias
    $MailboxStats.DisplayName = $Mailbox.DisplayName

	if ($Mailbox.IssueWarningQuota -eq 'unlimited')
	{
		$MailboxStats.IssueWarningQuota = $arrMbDbs | where {$_.Name -eq $Mailbox.Database} | foreach {$_.IssueWarningQuota}
		$MailboxStats.ProhibitSendQuota  = $arrMbDbs | where {$_.Name -eq $Mailbox.Database} | foreach {$_.ProhibitSendQuota}
		$MailboxStats.ProhibitSendReceiveQuota  = $arrMbDbs | where {$_.Name -eq $Mailbox.Database} | foreach {$_.ProhibitSendReceiveQuota}
	} else {
		MailboxStats.IssueWarningQuota = $Mailbox.IssueWarningQuota
		MailboxStats.ProhibitSendQuota =$Mailbox.ProhibitSendQuota
		MailboxStats.ProhibitSendReceiveQuota =$Mailbox.ProhibitSendReceiveQuota
	}

    $MailboxStats.TotalItemSize = $Stats.TotalItemSize
    $MailboxStats.ItemCount = $Stats.ItemCount
    $AllMailboxes += $MailboxStats
}
$AllMailboxes | Export-Csv C:\scripts\mailboxsizerestrictions.csv -NoTypeInformation

Open in new window


If you want a fast test, I would do the following, use the -Identity property on the Get-Mailbox and set it to:

1. a known user with non-custom quotas
2. a known user with custom quotas

and then replace the last line of the script with:

$AllMailboxes | out-Gridview

Open in new window


That should cover the 2 test cases.  The out-Gridview is just easier than constantly opening a csv.

Dan
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Powershell

From novice to tech pro — start learning today.