Skip to content

Commit 74ecd5f

Browse files
authored
Merge pull request KelvinTegelaar#1436 from kris6673/feat-EntraConnectSyncStatus-alert
Feat: Add EntraConnectSyncStatus alert
2 parents b1dea57 + 6998d43 commit 74ecd5f

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
2+
function Get-CIPPAlertEntraConnectSyncStatus {
3+
<#
4+
.FUNCTIONALITY
5+
Entrypoint
6+
#>
7+
[CmdletBinding()]
8+
param(
9+
[Parameter(Mandatory = $false)]
10+
[Alias('input')]
11+
$InputValue,
12+
$TenantFilter
13+
)
14+
try {
15+
# Set Hours with fallback to 72 hours
16+
$Hours = if ($InputValue) { [int]$InputValue } else { 72 }
17+
$ConnectSyncStatus = New-GraphGetRequest -uri 'https://graph.microsoft.com/beta/organization?$select=onPremisesLastPasswordSyncDateTime,onPremisesLastSyncDateTime,onPremisesSyncEnabled' -tenantid $TenantFilter
18+
19+
if ($ConnectSyncStatus.onPremisesSyncEnabled -eq $true) {
20+
$LastPasswordSync = $ConnectSyncStatus.onPremisesLastPasswordSyncDateTime
21+
$SyncDateTime = $ConnectSyncStatus.onPremisesLastSyncDateTime
22+
# Get the older of the two sync times
23+
$LastSync = if ($SyncDateTime -lt $LastPasswordSync) { $SyncDateTime } else { $LastPasswordSync }
24+
25+
if ($LastSync -lt (Get-Date).AddHours(-$Hours).ToUniversalTime()) {
26+
$AlertData = "Entra Connect Sync for $($TenantFilter) has not run for over $Hours hours. Last sync was at $($LastSync.ToString('o'))"
27+
Write-AlertTrace -cmdletName $MyInvocation.MyCommand -tenantFilter $TenantFilter -data $AlertData
28+
}
29+
}
30+
} catch {
31+
Write-AlertMessage -tenant $($TenantFilter) -message "Could not get Entra Connect Sync Status for $($TenantFilter): $(Get-NormalizedError -message $_.Exception.message)"
32+
}
33+
}

0 commit comments

Comments
 (0)