0 votes

I am looking for a solution to recognize in advance when the storage space of a shared mailbox is full and then a mail is sent Unfortunately, the report under Quotas, Limits and Restrictions does not provide the desired result. So far we have queried this manually via PS Script:


# Retrieve all shared mailboxes within the OU
$mailboxes = Get-Mailbox  -RecipientTypeDetails SharedMailbox

# Initiate the report
$report = @()

# Collect information for each mailbox in the OU
foreach ($mailbox in $mailboxes) {
    $mailboxUser = $mailbox.PrimarySmtpAddress

    # Retrieve mailbox statistics
    $mailboxStats = Get-MailboxStatistics -Identity $mailboxUser

    # Get the used mailbox size as a string and trim after the parentheses
    $usedSize = $mailboxStats.TotalItemSize.ToString() -replace '\s*\(.*$', ''

    # Retrieve maximum mailbox size from the quota property as a string (directly from the result)
    $maxSize = $mailbox.ProhibitSendReceiveQuota.ToString() -replace '\s*\(.*$', ''

    # Query archive size if available
    $archiveSize = "No archive available"
    if ($mailbox.ArchiveStatus -eq "Active") {
        $archiveStats = Get-MailboxStatistics -Identity "$mailboxUser" -Archive
        $archiveSize = $archiveStats.TotalItemSize.ToString() -replace '\s*\(.*$', ''
    }

    # Create report entry
    $reportEntry = @"

$mailboxUser
Used Size: $usedSize
Maximum Size: $maxSize
Archive: $archiveSize

"@

    # Add entry to the report
    $report += $reportEntry

}

# Write the entire report to a file
$reportFile = "$reportDir\SharedMailboxesReport.txt"
$report -join "`r`n" | Out-File -FilePath $reportFile -Encoding UTF8

Is there possibly a solution to query this automatically via Adaxes? Thanks!

by (530 points)

1 Answer

0 votes
by (289k points)

Hello Boris,

You can use the following script from our repository in a condition: https://www.adaxes.com/script-repository/check-mailbox-size-s450.htm. If the condition is met, the Send email notification action should be executed.

0

Hello Boris,

Thank you for the provided example. For us to write a script that will generate the report, please, provide us with a screenshot of the Multi-server environment dialog. The dialog displays how many Adaxes services you have and what their versions are. For information on how to view it, see https://www.adaxes.com/help/MultiServerEnvironment. You can post the screenshot here or send to us at support@adaxes.com.

0

Hello,

we have only one instance running: image.png

thanks for your support

0

Hello Boris,

Thank you for all the provided details. To achieve the desired, use the below script. To execute the script, create a report with a scope and no parameters. In the script:

  • $usedSizeColumnID - Specifies the identifier of the custom column that will contain the used mailbox space in Gb.
  • $maxSizeColumnID - Specifies the identifier of the custom column that will contain the maximum mailbox size in Gb.
  • $freeSizeColumnID - Specifies the identifier of the custom column that will contain the free mailbox space in Gb.
  • $usedSizeInPercentageColumnID - Specifies the identifier of the custom column that will contain the used mailbox space in percents.
  • $archiveSizeColumnID - - Specifies the identifier of the custom column that will contain the mailbox archive size in Gb.

To obtain a report custom column identifier:

  • On the Columns tab, right-click the custom column in the Report-specific columns section.
  • In the context menu, navigate to Copy and click Column ID.
  • The column identifier will be copied to clipboard.

For details on how to schedule reports, see https://www.adaxes.com/help/ScheduleReports.

$usedSizeColumnID = "{94bd8499-088d-43c2-bd1e-e1c1b7fa9f23}" # TODO: modify me
$maxSizeColumnID = "{c19d2faa-c0f6-4071-9f81-cd461b31738b}" # TODO: modify me
$freeSizeColumnID = "{73a25196-887b-44aa-aca5-372248248e42}" # TODO: modify me
$usedSizeInPercentageColumnID = "{93cbc727-11d8-4e8a-adf5-6934469a2126}" # TODO: modify me
$archiveSizeColumnID = "{550e1ce1-e633-46fb-ae09-3941ff8c094e}" # TODO: modify me

$criteria = New-AdmCriteria "user" {mailboxType -eq "shared"}
$Context.DirectorySearcher.AddCriteria($criteria)
try
{
    $searchIterator = $Context.DirectorySearcher.ExecuteSearch()
    while ($Context.MoveNext($searchIterator))
    {
        $searchResult = $searchIterator.Current
        $user = $Context.BindToObjectBySearchResult($searchResult)

        # Get Exchange properties
        try
        {
            $mailboxParams = $user.GetMailParameters()
        }
        catch
        {
            $Context.LogMessage($_.Exception.Message, "Warning")
            continue
        }

        # Check quotas
        if ($NULL -eq $mailboxParams.StorageQuotas.ProhibitSendReceiveQuota)
        {
            continue
        }

        # Get mailbox size and max size
        $mailboxSizeGB = $mailboxParams.UsageInfo.Size.GetGBytes()
        $maxSizeGB = $mailboxParams.StorageQuotas.ProhibitSendReceiveQuota.GetGBytes()

        # Skip less than 90 percentage
        $usedSizeInPercentage = [System.Math]::Round(($mailboxSizeGB/$maxSizeGB)*100)
        if ($usedSizeInPercentage -lt 90)
        {
            continue
        }

        # Get free size
        $freeSizeGB = $maxSizeGB - $mailboxSizeGB

        # Get Archive size
        # Get properties of the 'Archiving' feature
        $archiving = $mailboxParams.MailboxFeatures.GetItemByType("ADM_EXCHANGE_MAILBOXFEATURETYPE_ARCHIVE")
        if ($archiving.Enabled -and $NULL -ne $archiving.Size)
        {
            $archiveSizeGB = $archiving.Size.GetGBytes()
        }
        else
        {
            $archiveSizeGB = $NULL
        }

        $customColumns = @{
            $usedSizeColumnID = [System.Math]::Round($mailboxSizeGB, 4)
            $maxSizeColumnID = [System.Math]::Round($maxSizeGB, 4)
            $freeSizeColumnID = [System.Math]::Round($freeSizeGB, 4)
            $usedSizeInPercentageColumnID = $usedSizeInPercentage
            $archiveSizeColumnID = [System.Math]::Round($archiveSizeGB, 4)
        }
        $Context.Items.Add($searchResult, $customColumns, $NULL)
    }
}
finally
{
    if ($searchIterator) { $searchIterator.Dispose() }
}
0

Hello Support,

Thank you very much for the time and effort you have invested, the script fulfills my requirements perfectly. :) Unfortunately it is stopping with "The pipeline has been stopped", after some minutes I have set the scope to "specific location" and "direct children", which contains ~200 Mailboxes. Any thing else I could do, to avoid the error?

image.png

0

Hello Boris,

The error occurs because executing the script takes longer than 10 minutes which is the default timeout. You can change the timeout, but it can only be done for all scripts.

Related questions

0 votes
0 answers

We currently convert user mailboxes to shared mailboxes during deprovisioning process but if the user mailbox was already a shared mailbox then the script throws an error ... user mailbox. Here is the actions of the current deprovision command: Thanks!

asked Oct 1 by Carlos (40 points)
0 votes
1 answer

So if we change the flow on the exisitng deprovision script to the above, is there a way to set a retention policy tag to the converted mailbox? Our standard retention is 90 days.

asked Sep 19 by EnbyAdmin (60 points)
0 votes
1 answer

Good afternoon, Is there a script for adding a user to an already existing Office 365 Shared Mailbox? I want to add this script onto the onboarding rules I have added already.

asked May 7 by ocanizales (60 points)
0 votes
1 answer

I'd like some help with a script to revoke a users rights to a shared mailbox upon being removed from a security group. I already have the reverse, a script that adds users to a shared mailbox, if they are a member of a group, now I just need the reverse.

asked Mar 20 by dominik.stawny (280 points)
0 votes
1 answer

We have a "Create Shared Mailbox" function which uses a custom command in PS. I've amended my PS script to created Shared Mailboxes to be inline with the V3 of Exchange ... issue? Here's the script And here's the error after using the the function once.

asked Jun 13, 2023 by Homelander90 (350 points)
3,548 questions
3,238 answers
8,232 comments
547,814 users