Script Repository


All mailbox delegates

June 30, 2017
744

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

To schedule a report, create a Scheduled Task configured for the Domain-DNS 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($filter, $properties)
{
    $searcher = $Context.BindToObject("Adaxes://rootDSE")
    $searcher.SearchFilter = $filter
    $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
$searchResults = SearchObjects "(&(sAMAccountType=805306368)(publicDelegates=*))" @("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 ( 0 )
No results found.
Leave a comment