#Requires -Modules ADSync <# .SYNOPSIS Śledzi konkretny obiekt przez pipeline ADConnect — diagnozuje problemy synchronizacji. .DESCRIPTION Dla podanego użytkownika lub obiektu AD pokazuje: - Czy obiekt jest w Connector Space AD - Czy jest w Metaverse - Czy jest w Connector Space AAD - Aktualny status eksportu - Atrybuty i ich wartości w CS/MV - Przyczynę braku synchronizacji (jeśli dotyczy) Kluczowy skrypt do diagnozowania "dlaczego ten user nie synchronizuje się do Azure AD". .PARAMETER UserPrincipalName UPN użytkownika do śledzenia (np. jan.kowalski@firma.pl). .PARAMETER SamAccountName Alternatywnie — SamAccountName użytkownika. .EXAMPLE .\Get-ADConnectObjectTrace.ps1 -UserPrincipalName jan.kowalski@firma.pl .\Get-ADConnectObjectTrace.ps1 -SamAccountName jkowalski #> param( [string]$UserPrincipalName, [string]$SamAccountName ) Import-Module ADSync -ErrorAction Stop Import-Module ActiveDirectory -ErrorAction Stop if (-not $UserPrincipalName -and -not $SamAccountName) { Write-Error "Podaj -UserPrincipalName lub -SamAccountName" return } # Pobierz DN obiektu z AD $adUser = if ($SamAccountName) { Get-ADUser -Identity $SamAccountName -Properties UserPrincipalName, DistinguishedName, Enabled, msDS-cloudExtensionAttribute1 -ErrorAction Stop } else { Get-ADUser -Filter "UserPrincipalName -eq '$UserPrincipalName'" -Properties UserPrincipalName, DistinguishedName, Enabled -ErrorAction Stop } if (-not $adUser) { Write-Error "Nie znaleziono użytkownika w AD." return } Write-Host "`n========================================" -ForegroundColor Cyan Write-Host " ŚLEDZENIE OBIEKTU ADConnect" -ForegroundColor Cyan Write-Host " $($adUser.DisplayName) [$($adUser.SamAccountName)]" -ForegroundColor Cyan Write-Host "========================================`n" -ForegroundColor Cyan Write-Host "--- OBIEKT W ACTIVE DIRECTORY ---" -ForegroundColor Yellow [PSCustomObject]@{ DN = $adUser.DistinguishedName UPN = $adUser.UserPrincipalName Enabled = $adUser.Enabled } | Format-List # Konektor AD $adConnector = Get-ADSyncConnector | Where-Object { $_.Type -notlike '*Extensible*' -and $_.Type -ne 'Azure Active Directory' } | Select-Object -First 1 # Konektor AAD $aadConnector = Get-ADSyncConnector | Where-Object { $_.Type -like '*Extensible*' -or $_.Name -like '*AAD*' -or $_.Name -like '*Azure*' } | Select-Object -First 1 Write-Host "--- CONNECTOR SPACE (AD Connector: $($adConnector?.Name)) ---" -ForegroundColor Yellow try { $csAD = Get-ADSyncCSObject -ConnectorName $adConnector.Name -DistinguishedName $adUser.DistinguishedName -ErrorAction Stop if ($csAD) { Write-Host " [OK] Obiekt znaleziony w CS AD." -ForegroundColor Green Write-Host " Connector ID : $($csAD.ConnectorId)" Write-Host " ObjectType : $($csAD.ObjectType)" Write-Host " IsFiltered : $($csAD.IsFiltered)" -ForegroundColor $(if ($csAD.IsFiltered) { 'Red' } else { 'Green' }) Write-Host " Pending Export: $($csAD.PendingExport)" Write-Host " ExportError : $(if ($csAD.ExportError) { $csAD.ExportError } else { 'Brak' })" if ($csAD.IsFiltered) { Write-Host "`n UWAGA: Obiekt jest odfiltrowany — nie będzie synchronizowany!" -ForegroundColor Red Write-Host " Sprawdź: reguły filtrowania w Synchronization Rules Editor" -ForegroundColor Yellow } } } catch { Write-Host " [BRAK] Obiektu nie ma w Connector Space AD." -ForegroundColor Red Write-Host " Przyczyna: $_" } Write-Host "`n--- METAVERSE ---" -ForegroundColor Yellow try { $mvObjects = Search-ADSyncMVObject -AttributeName userPrincipalName -AttributeValue $adUser.UserPrincipalName -ErrorAction SilentlyContinue if (-not $mvObjects -and $adUser.SamAccountName) { $mvObjects = Search-ADSyncMVObject -AttributeName accountName -AttributeValue $adUser.SamAccountName -ErrorAction SilentlyContinue } if ($mvObjects) { Write-Host " [OK] Obiekt w Metaverse." -ForegroundColor Green $mvObjects | Select-Object -First 1 | ForEach-Object { Write-Host " MV Identifier: $($_.Identifier)" Write-Host " ObjectType : $($_.ObjectType)" } } else { Write-Host " [BRAK] Obiekt nie istnieje w Metaverse." -ForegroundColor Red Write-Host " Możliwe przyczyny:" -ForegroundColor Yellow Write-Host " 1. Obiekt jest odfiltrowany przez reguły scoping" -ForegroundColor Yellow Write-Host " 2. Synchronizacja jeszcze nie dotarła do tego obiektu" -ForegroundColor Yellow Write-Host " 3. OU obiektu jest wykluczona z synchronizacji" -ForegroundColor Yellow } } catch { Write-Host " Błąd przy szukaniu w Metaverse: $_" -ForegroundColor Red } # Sprawdź AAD CS Write-Host "`n--- CONNECTOR SPACE (AAD Connector: $($aadConnector?.Name)) ---" -ForegroundColor Yellow Write-Host " Sprawdź ręcznie w: Synchronization Service Manager → Connectors → $($aadConnector?.Name) → Search Connector Space" Write-Host " Filtruj po: $($adUser.UserPrincipalName)" Write-Host "`n--- CHECKLIST DIAGNOSTYCZNY ---" -ForegroundColor Cyan Write-Host " [ ] Czy OU użytkownika jest w zakresie synchronizacji?" Write-Host " [ ] Czy użytkownik ma poprawny UPN suffix (@domena.pl)?" Write-Host " [ ] Czy nie ma konfliktu UPN z innym obiektem w AAD?" Write-Host " [ ] Czy atrybuty wymagane (mail, upn) są uzupełnione?" Write-Host " [ ] Czy adres email nie duplikuje innego konta?" Write-Host " [ ] Czy konto nie jest wykluczone przez filtr atrybutowy?" Write-Host " [ ] Kiedy ostatnio wykonano delta sync? (Get-ADSyncScheduler)"