You can use this as a guide:
https://office365itpros.com/2025/01/21/azure-automation-runbook-primer/
You can then create a task to check this against the last time the sync was successful in Entra:
(Get-MgOrganization -Property OnPremisesLastSyncDateTime).OnPremisesLastSyncDateTime
Ignore the _ in the beginning and end of that command sample
_(Get-MgOrganization -Property OnPremisesLastSyncDateTime).OnPremisesLastSyncDateTime_