How to set an event when admin gives delegation to shared mailbox

Mani 376 Reputation points
2025-02-09T22:10:01.6666667+00:00

Hello all,While giving delegation to Terminated user shared mailbox we want to make it for 60days and then need to follow up with the delegate on next step to remove or extend the delegation

To get this is there a way to create an event after 60days of giving delegation to shared mailbox with all details to our mailbox.

I tried office alerts but it's not giving all details.

Please suggest if any one have some automated scripts or any other solution to achive this.

Thanks in advance

Microsoft Exchange Online
Microsoft Exchange Online Management
Microsoft Exchange Online Management
Microsoft Exchange Online: A Microsoft email and calendaring hosted service.Management: The act or process of organizing, handling, directing or controlling something.
4,758 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Alex Zhang-MSFT 5,300 Reputation points Microsoft Vendor
    2025-02-10T05:09:13.8566667+00:00

    Hello, @Mani,

    Welcome to the Microsoft Q&A platform!

    From Exchange's native configuration there isn’t a built‐in mechanism to track when a delegation was assigned (and thus no native “expiry” event) or to automatically trigger reminders based solely on a 60-day interval. Perhaps you can try to handle this directly from Exchange by custom scripting.

    Here's a way to automate the delegation and set a reminder using PowerShell:

    1. Assign Delegation: Use the Add-MailboxPermission cmdlet to assign the delegation.
    2. Set a Reminder: You can use a scheduled task to run a PowerShell script that checks for delegations that are about to expire and sends a reminder email.
    # Assign delegation
    Add-MailboxPermission -Identity "SharedMailbox" -User "DelegateUser" -AccessRights FullAccess -InheritanceType All
    
    # Schedule a task to run after 60 days
    $action = New-ScheduledTaskAction -Execute 'Powershell.exe' -Argument '-File "C:\Scripts\CheckDelegation.ps1"'
    $trigger = New-ScheduledTaskTrigger -At (Get-Date).AddDays(60) -Once
    Register-ScheduledTask -Action $action -Trigger $trigger -TaskName "CheckDelegation"
    
    # Create the CheckDelegation.ps1 script
    $scriptContent = @"
    # CheckDelegation.ps1
    # Script to check delegation and send reminder
    
    # Your logic to check delegation
    # Example: Send an email reminder
    Send-MailMessage -To "your-email@example.com" -Subject "Delegation Reminder" -Body "Please review the delegation for SharedMailbox." -SmtpServer "smtp.example.com"
    "@
    Set-Content -Path "C:\Scripts\CheckDelegation.ps1" -Value $scriptContent
    

    This script will:

    1. Assign the delegation.
    2. Schedule a task to run a script after 60 days.
    3. The scheduled script will send a reminder email.

    Since it is very difficult for exchange to try to automate on this issue, if it fails, I suggest using Power Automate to finish this. For reference, please refer to Automate Shared Mailbox Requests Using Azure Logic Apps.

    (Note: Microsoft provides third-party contact information to help you find additional information about this topic. This contact information may change without notice. Microsoft does not guarantee the accuracy of third-party contact information.)

    Should you need more help on this, you can feel free to post back. 


    If the answer is helpful, please click on “Accept answer” as it could help other members of the Microsoft Q&A community who have similar questions and are looking for solutions.

    Thank you for your support and understanding.

    Best Wishes,

    Alex Zhang


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.