We use cookies to improve your experience.
By your continued use of this site you accept such use.
For more details please see our privacy policy and cookies policy.

Script Repository

All mailbox delegates

October 18, 2023 Views: 2336

The script creates a CSV-formatted report on delegates of on-premises Exchange mailboxes in all domains managed by Adaxes.

To schedule a report, create a scheduled task configured for the Domain object type that runs the script and assign it over any of your AD domains. To add the script to a scheduled task, use the Run a program or PowerShell script action.

Parameter:

  • $csvFilePath - Specifies a full path to the CSV file containing the report.
Edit Remove
PowerShell
$csvFilePath = "\\Server\Share\MailboxDelegates.csv" # TODO: modify me

function SearchObjects($criteria, $properties)
{
    $searcher = $Context.BindToObject("Adaxes://rootDSE")
    $searcher.Criteria = $criteria
    $searcher.SearchScope = "ADS_SCOPE_SUBTREE"
    $searcher.PageSize = 500
    $searcher.ReferralChasing = "ADS_CHASE_REFERRALS_NEVER"
    $searcher.SetPropertiesToLoad($properties)
    $searcher.VirtualRoot = $True
    
    try
    {
        $searchResultIterator = $searcher.ExecuteSearch()
        $searchResults = $searchResultIterator.FetchAll()
        
        return ,$searchResults
    }
    finally
    {
        # Release resources
        if ($searchResultIterator){ $searchResultIterator.Dispose() }
    }
}

# Search mailbox
$criteria = New-AdmCriteria "user" -Expression {publicDelegates -empty $False}
$searchResults = SearchObjects $criteria @("publicDelegates")

# Build report
$report = New-Object System.Collections.ArrayList
foreach ($searchResult in $searchResults)
{
    # Get mailbox name.
    $mailboxDisplayName = $Context.GetDisplayNameFromAdsPath($searchResult.AdsPath)

    $publicDelegates = $searchResult.Properties["publicDelegates"].Values
    for ($i = 0; $i -lt $publicDelegates.Count; $i++)
    {
        # Get object name.
        $displayName = $Context.GetDisplayNameFromAdsPath("Adaxes://$($publicDelegates[$i])")
        
        # Build record
        $record = New-Object PSObject
        $record | Add-Member -Membertype NoteProperty -Name "Mailbox name" -Value $mailboxDisplayName
        $record | Add-Member -Membertype NoteProperty -Name "ResourceDelegates" -Value $displayName
        
        # Add record to the report
        $report.Add($record)
    }
}

# Export to CSV file
$report | Export-Csv $csvFilePath -NoTypeInformation

Comments 2
avatar
Ray Bilyk Oct 17, 2023
Will this work with mailboxes in Exchange Online?
avatar
Support Oct 18, 2023
Hello Ray,

No, the script will not work for pure Exchange Online mailboxes. Unfortunately, there is no easy way to do that.
Leave a comment
Loading...

Got questions?

Support Questions & Answers