This guide explains how to set up an Azure Automation Account to automatically identify Guest users who have not logged in for over 180 days, and send a summary report via a Shared Mailbox.
This solution operates entirely headlessly using a System-Assigned Managed Identity and the Microsoft Graph API.
🔍 Click image to open full-resolution version in a new tab
Because you cannot assign Microsoft Graph Application permissions to a Managed Identity via the Azure Portal GUI, you must use PowerShell.
Open an administrative PowerShell console, ensure the Microsoft.Graph module is installed, download and run the script from this repository:
👉 Grant-GraphAPIPermissions.ps1
Be sure to replace
$AppNamewith the exact name of your Automation Account.
Get-StaleGuestAccounts), set the Runbook type to PowerShell, and set the Runtime version to 5.1 (or 7.2).Remember to update the configuration variables at the top of the script with your specific Group ID and email addresses.
Navigate to Shared Resources > Schedules and click Add a schedule (e.g., “Weekly on Mondays”).
Go back to your published Runbook, click Link to schedule, and attach your new schedule.