A cloud-based identity and access management service for securing user authentication and resource access
Hey Ravi,
You can totally build a little PowerShell wrapper around the built-in ADSync module to grab your last sync status (and even take a screenshot) and then ship the results off via SMTP or a Teams webhook. Below is a sample script you can use as a starting point. Feel free to tweak paths, SMTP/Teams settings, etc.
— SAMPLE SCRIPT —
# 1) Load the AAD Connect Sync cmdlets
Import-Module ADSync
# 2) Get your scheduler info
$scheduler = Get-ADSyncScheduler
# 3) Build an object with the bits we care about
$status = [PSCustomObject]@{
SyncEnabled = if ($scheduler.SyncCycleEnabled) { "Enabled" } else { "Disabled" }
LastSync = $scheduler.LastRunStatusTimestamp
NextSync = $scheduler.NextSyncCyclePolicyType
Version = (Get-Command Get-ADSyncScheduler).ModuleVersion
}
# 4) (Optional) Take a screenshot of your console and save to file
Add-Type -AssemblyName System.Windows.Forms,System.Drawing
$bounds = [System.Windows.Forms.Screen]::PrimaryScreen.Bounds
$bmp = New-Object System.Drawing.Bitmap $bounds.Width, $bounds.Height
$gfx = [System.Drawing.Graphics]::FromImage($bmp)
$gfx.CopyFromScreen($bounds.Location, [System.Drawing.Point]::Empty, $bounds.Size)
$screenshotPath = "C:\Temp\EntraSyncStatus.png"
$bmp.Save($screenshotPath, [System.Drawing.Imaging.ImageFormat]::Png)
# 5) Turn status into an HTML table
$htmlBody = @"
<html>
<body>
<h2>Microsoft Entra Connect Sync Status</h2>
<table border="1" cellpadding="4">
<tr><th>Sync Enabled</th><td>$($status.SyncEnabled)</td></tr>
<tr><th>Last Sync</th> <td>$($status.LastSync)</td></tr>
<tr><th>Next Sync</th> <td>$($status.NextSync)</td></tr>
<tr><th>Module Version</th><td>$($status.Version)</td></tr>
</table>
<p>See attached screenshot for a quick visual.</p>
</body>
</html>
"@
# 6A) Send via SMTP
$smtpParams = @{
SmtpServer = 'smtp.yourdomain.com'
From = '******@yourdomain.com'
To = '******@yourdomain.com'
Subject = 'Entra Connect Sync Status'
Body = $htmlBody
BodyAsHtml = $true
Attachments = $screenshotPath
}
Send-MailMessage @smtpParams
# 6B) OR post to Teams via Incoming Webhook
$webhookUrl = 'https://outlook.office.com/webhook/…' # your channel’s webhook
$card = @{
'@type' = 'MessageCard'
'@context' = 'http://schema.org/extensions'
themeColor = '0076D7'
summary = 'Entra Connect Sync Status'
sections = @(
@{
activityTitle = "Entra Connect Sync Status"
facts = @(
@{ name = 'Sync Enabled'; value = $status.SyncEnabled }
@{ name = 'Last Sync' ; value = $status.LastSync }
@{ name = 'Next Sync' ; value = $status.NextSync }
@{ name = 'Version' ; value = $status.Version }
)
markdown = $true
}
)
}
$cardJson = $card | ConvertTo-Json -Depth 5
Invoke-RestMethod -Uri $webhookUrl -Method Post -ContentType 'application/json' -Body $cardJson
Hope that helps you get up and running quickly!
— REFERENCES —
- Connect Health for Microsoft Entra Synchronization https://docs.microsoft.com/azure/active-directory/connect/active-directory-aadconnect-health-operations
- Enable email notifications for Entra Connect Health alerts https://docs.microsoft.com/azure/active-directory/hybrid/how-to-connect-health-operations#enable-email-notifications
- ADSync PowerShell cmdlets (Get-ADSyncScheduler, etc.) https://docs.microsoft.com/powershell/module/adsync/get-adsyncscheduler
Let me know if you need help with SMTP details, Teams webhook setup or tweaking the screenshot logic!
Note: This content was drafted with the help of an AI system. Please verify the information before relying on it for decision-making.
If the resolution was helpful, kindly take a moment to click on
and click on Yes for was this answer helpful. And, if you have any further query do let us know.