Share via

MS Azure Entra Connect Sync Status automation

Ravi Kiran Moole 120 Reputation points
2026-05-28T10:47:38.3633333+00:00

Hello Team!

I am looking for a PS Script which can share the "MS Azure Entra Connect Sync Status" with screenshot if possible as shown below and giving the last sync status as well, attached is the screenshot for reference.

I am looking for script which will give the status and sends an email message or MS Teams chat post in a channel for monitoring purpose.

User's image

Microsoft Security | Microsoft Entra | Microsoft Entra ID

Answer accepted by question author

Rukmini 42,010 Reputation points Microsoft External Staff Moderator
2026-05-28T12:30:05.2+00:00

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 —

  1. Connect Health for Microsoft Entra Synchronization https://docs.microsoft.com/azure/active-directory/connect/active-directory-aadconnect-health-operations
  2. Enable email notifications for Entra Connect Health alerts https://docs.microsoft.com/azure/active-directory/hybrid/how-to-connect-health-operations#enable-email-notifications
  3. 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 210246-screenshot-2021-12-10-121802.pngand click on Yes for was this answer helpful. And, if you have any further query do let us know.

Was this answer helpful?

1 person found this answer helpful.

Answer accepted by question author

AI answer

2026-05-28T10:48:01.2666667+00:00

Microsoft Entra Connect Health for Sync exposes the sync status, last sync time, and sync trends that can be queried and then used in automation.

To automate monitoring and notifications, use the following approach:

  1. Install and configure Microsoft Entra Connect Health for Sync on each Entra Connect Sync server as a prerequisite.
    • Install the Microsoft Entra Connect Health agent on every Microsoft Entra Connect Sync server (Windows Server 2016 or later) and ensure the server is running Microsoft Entra Connect Sync V2.
  2. Use the Connect Health Sync insights as the data source:
    • The Sync Insight feature provides:
      • Latency of sync operations (import/export) per connector.
      • Object change trends and failures being exported to Microsoft Entra ID.
    • These metrics give the equivalent of the portal “Sync status” and “Last sync” view, but in a form that can be queried and evaluated in automation.
  3. Scripted monitoring pattern (high level):
    • Use PowerShell to query the sync job status and health data, then send notifications:
      1. Query sync job status and last run information via Microsoft Graph / Connect Health APIs (for example, using the same underlying data that powers the Sync Latency and Sync Object Changes charts).
      2. Evaluate conditions such as:
        • Last successful export older than the desired threshold.
        • Latency or error counts above expected levels.
      3. If thresholds are breached, send a notification:
        • Email: use Send-MailMessage or an SMTP/Graph-based mail cmdlet in the script.
        • Teams: call a Logic App or webhook that posts to a Teams channel.
  4. Optional: use Logic Apps for Teams notifications:
    • Create a Logic App that posts to Teams using the “Post message in a chat or channel” action.
    • Configure it to:
      • Post as: Flow bot.
      • Post in: Chat with Flow bot or a specific channel.
      • Include dynamic content from the monitoring script (status text, last sync time, error summary).
      • Optionally set IsAlert so the message appears in the Teams activity feed.
    • Trigger the Logic App from the PowerShell script (for example, via an HTTP trigger) when a sync issue is detected.
  5. Screenshot requirement:
    • The Connect Health portal already provides graphical views:
      • Sync Latency chart (run profile latency over time).
      • Sync Object Changes chart (export statistics and failures).
    • A script can periodically export or capture these charts (for example, via scheduled browser automation) and attach them to email or Teams messages, but this is an additional automation layer on top of the Connect Health data.

This design gives a fully automated monitoring solution: Connect Health for Sync as the authoritative data source, PowerShell to evaluate status and last sync, and email/Teams (via Logic Apps) for alerts.


References:

AI-generated content may be incorrect. Read our transparency notes for more information.

Was this answer helpful?

1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

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