{"id":173,"title":"Active Directory Replikasyon \u0130\u00e7in Kullan\u0131lacak Scriptler","content":"Active Directory Replikasyon \u0130\u00e7in Kullan\u0131lacak Scriptler <ul> <li><strong>Test-ADReplicationHealth<\/strong><\/li> <li><strong>Remove-LingeringObjects<\/strong><\/li> <li><strong>Get-ADReplicationPerformance<\/strong><\/li> <li><strong>Get-TombstoneLifetime<\/strong><\/li> <\/ul> # 1. Replikasyon Sa\u011fl\u0131k Kontrol\u00fc ve Raporlama function Test-ADReplicationHealth { param ( $LogPath = \"C:\\Logs\\ADReplication\", $EmailTo = \"admin@domain.com\", $WarningThreshold = 45 \u00a0# minutes ) Begin { # Log klas\u00f6r\u00fc olu\u015ftur if (-not (Test-Path $LogPath)) { New-Item -ItemType Directory -Path $LogPath } $timestamp = Get-Date -Format \"yyyy-MM-dd_HH-mm\" $logFile = Join-Path $LogPath \"ADReplication_$timestamp.log\" $htmlReport = Join-Path $LogPath \"ADReplication_$timestamp.html\" # HTML rapor ba\u015fl\u0131\u011f\u0131 $htmlHeader = @\" &lt;style&gt; table { border-collapse: collapse; width: 100%; } th, td { border: 1px solid black; padding: 8px; text-align: left; } th { background-color: #4CAF50; color: white; } tr:nth-child(even) { background-color: #f2f2f2; } .critical { background-color: #ff9999; } .warning { background-color: #ffeb99; } &lt;\/style&gt; \"@ } Process { try { # T\u00fcm Domain Controller'lar\u0131 al $DCs = Get-ADDomainController -Filter * $results = @() foreach ($DC in $DCs) { Write-Verbose \"Checking replication status for $($DC.HostName)\" # Replikasyon durumunu kontrol et $replStatus = repadmin \/showrepl $DC.HostName \/csv | ConvertFrom-Csv # DC'nin eri\u015filebilirli\u011fini kontrol et $pingStatus = Test-Connection -ComputerName $DC.HostName -Count 1 -Quiet # DC servisleri kontrol et $services = @(\"NTDS\", \"DNS\", \"Netlogon\", \"W32Time\") $serviceStatus = @{} foreach ($service in $services) { try { $status = Get-Service -ComputerName $DC.HostName -Name $service -ErrorAction Stop $serviceStatus = $status.Status } catch { $serviceStatus = \"Error\" } } # Son replikasyon zaman\u0131n\u0131 al $lastRepl = ($replStatus | Where-Object { $_.SourceDSA -ne $DC.HostName } | Measure-Object \"Last Success Time\" -Maximum).Maximum $results += @{ DomainController = $DC.HostName Site \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0= $DC.Site IP \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0= $DC.IPv4Address Online \u00a0 \u00a0 \u00a0 \u00a0 \u00a0= $pingStatus LastReplication = $lastRepl NTDSStatus \u00a0 \u00a0 \u00a0= $serviceStatus DNSStatus \u00a0 \u00a0 \u00a0 = $serviceStatus NetlogonStatus \u00a0= $serviceStatus TimeStatus \u00a0 \u00a0 \u00a0= $serviceStatus FailureCount \u00a0 \u00a0= ($replStatus | Where-Object { $_.\"Number of Failures\" -gt 0 }).Count } # Log dosyas\u0131na yaz \"$(Get-Date -Format 'yyyy-MM-dd HH:mm:ss'): Checked $($DC.HostName)\" | Out-File $logFile -Append } # HTML raporu olu\u015ftur $htmlBody = $results | ConvertTo-Html -Head $htmlHeader -PreContent \"&lt;h1&gt;AD Replication Status Report&lt;\/h1&gt;&lt;h3&gt;Generated: $(Get-Date)&lt;\/h3&gt;\" $htmlBody | Out-File $htmlReport # Kritik durumlar\u0131 kontrol et ve email g\u00f6nder $criticalIssues = $results | Where-Object { -not $_.Online -or $_.FailureCount -gt 0 -or $_.NTDSStatus -ne \"Running\" } if ($criticalIssues) { $emailBody = \"Critical AD Replication Issues Detected:`n`n\" $emailBody += $criticalIssues | Format-Table | Out-String Send-MailMessage -To $EmailTo ` -Subject \"AD Replication Alert: Critical Issues Detected\" ` -Body $emailBody ` -BodyAsHtml ` -Attachments $htmlReport } return $results } catch { Write-Error \"Error occurred: $_\" \"$(Get-Date -Format 'yyyy-MM-dd HH:mm:ss'): ERROR - $_\" | Out-File $logFile -Append } } } # 2. Lingering Object Tespit ve Temizleme function Remove-LingeringObjects { param ( $SourceDC, $TargetDC, $Advisory, $LogPath = \"C:\\Logs\\LingeringObjects\" ) Begin { if (-not (Test-Path $LogPath)) { New-Item -ItemType Directory -Path $LogPath } $timestamp = Get-Date -Format \"yyyy-MM-dd_HH-mm\" $logFile = Join-Path $LogPath \"LingeringObjects_$timestamp.log\" } Process { try { # DC'lerin eri\u015filebilirli\u011fini kontrol et $sourcePing = Test-Connection -ComputerName $SourceDC -Count 1 -Quiet $targetPing = Test-Connection -ComputerName $TargetDC -Count 1 -Quiet if (-not ($sourcePing -and $targetPing)) { throw \"One or both DCs are not reachable\" } # Target DC'nin GUID'ini al $targetDCObj = Get-ADDomainController $TargetDC $targetGuid = $targetDCObj.ObjectGUID # Naming Context'leri al $namingContexts = (Get-ADRootDSE -Server $SourceDC).namingContexts foreach ($nc in $namingContexts) { \"$(Get-Date -Format 'yyyy-MM-dd HH:mm:ss'): Processing $nc\" | Out-File $logFile -Append if ($Advisory) { # Advisory mode - sadece raporla $cmd = \"repadmin \/removelingeringobjects $SourceDC $targetGuid `\"$nc`\" \/ADVISORY_MODE\" $result = Invoke-Expression $cmd $result | Out-File $logFile -Append } else { # Ger\u00e7ek temizlik if ($PSCmdlet.ShouldProcess($nc, \"Remove lingering objects\")) { $cmd = \"repadmin \/removelingeringobjects $SourceDC $targetGuid `\"$nc`\"\" $result = Invoke-Expression $cmd $result | Out-File $logFile -Append } } } # Sonu\u00e7lar\u0131 raporla Get-Content $logFile } catch { Write-Error \"Error occurred: $_\" \"$(Get-Date -Format 'yyyy-MM-dd HH:mm:ss'): ERROR - $_\" | Out-File $logFile -Append } } } # 3. Replikasyon Performans \u0130zleme function Get-ADReplicationPerformance { param ( $SampleInterval = 5, \u00a0# seconds $SampleCount = 12, $LogPath = \"C:\\Logs\\ADPerformance\" ) Begin { if (-not (Test-Path $LogPath)) { New-Item -ItemType Directory -Path $LogPath } $timestamp = Get-Date -Format \"yyyy-MM-dd_HH-mm\" $logFile = Join-Path $LogPath \"ADPerformance_$timestamp.csv\" $counters = @( \"\\DirectoryServices\\DS Directory Reads\/sec\", \"\\DirectoryServices\\DS Directory Writes\/sec\", \"\\DirectoryServices\\LDAP Client Sessions\", \"\\DirectoryServices\\LDAP Bind Time\", \"\\DirectoryServices\\DRA Pending Replication Operations\", \"\\DirectoryServices\\DRA Pending Replication Synchronizations\" ) } Process { try { $results = Get-Counter -Counter $counters -SampleInterval $SampleInterval -MaxSamples $SampleCount | Select-Object -ExpandProperty CounterSamples | Select-Object Path, CookedValue, TimeStamp # CSV'ye kaydet $results | Export-Csv -Path $logFile -NoTypeInformation # \u00d6zet istatistikler hesapla $summary = $results | Group-Object Path | ForEach-Object { $values = $_.Group.CookedValue @{ Counter \u00a0 \u00a0 = $_.Name Average \u00a0 \u00a0= ($values | Measure-Object -Average).Average Maximum \u00a0 \u00a0= ($values | Measure-Object -Maximum).Maximum Minimum \u00a0 \u00a0= ($values | Measure-Object -Minimum).Minimum Samples \u00a0 \u00a0= $values.Count } } return $summary } catch { Write-Error \"Error occurred: $_\" } } } # 4. Tombstone Lifetime \u0130zleme function Get-TombstoneLifetime { param ( $WarningThreshold = 45, \u00a0# days $EmailTo = \"admin@domain.com\" ) Process { try { # Forest yap\u0131land\u0131rmas\u0131n\u0131 al $forest = Get-ADForest $rootDomain = $forest.RootDomain # Tombstone Lifetime de\u011ferini al $searchBase = \"CN=Directory Service,CN=Windows NT,CN=Services,CN=Configuration,$((Get-ADDomain $rootDomain).DistinguishedName)\" $tombstoneLifetime = Get-ADObject -SearchBase $searchBase -Filter {objectClass -eq \"dSHeuristics\"} -Properties tombstoneLifetime $result = @{ ForestName = $forest.Name TombstoneLifetime = if ($tombstoneLifetime.tombstoneLifetime) { $tombstoneLifetime.tombstoneLifetime } else { 60 \u00a0# default value } Status = \"OK\" LastChecked = Get-Date } # Warning kontrol\u00fc if ($result.TombstoneLifetime -lt $WarningThreshold) { $result.Status = \"Warning\" # Email uyar\u0131s\u0131 g\u00f6nder $emailBody = @\" Warning: Tombstone Lifetime is set to $($result.TombstoneLifetime) days. Recommended minimum is $WarningThreshold days. Forest: $($result.ForestName) Checked: $($result.LastChecked) \"@ Send-MailMessage -To $EmailTo ` -Subject \"AD Tombstone Lifetime Warning\" ` -Body $emailBody } return $result } catch { Write-Error \"Error occurred: $_\" } } } # Kullan\u0131m \u00f6rnekleri: # 1. Replikasyon sa\u011fl\u0131k kontrol\u00fc # Test-ADReplicationHealth -Verbose # 2. Lingering object temizli\u011fi (Advisory mode) # Remove-LingeringObjects -SourceDC \"DC1\" -TargetDC \"DC2\" -Advisory # 3. Performans izleme # Get-ADReplicationPerformance -SampleInterval 10 -SampleCount 6 # 4. Tombstone lifetime kontrol\u00fc # Get-TombstoneLifetime -WarningThreshold 50 ``` Bu PowerShell scriptleri \u015funlar\u0131 i\u00e7erir: 1. **Test-ADReplicationHealth** - T\u00fcm DC'lerin replikasyon durumunu kontrol eder - HTML ve log dosyas\u0131 olu\u015fturur - Kritik durumlarda email atar - Servis durumlar\u0131n\u0131 kontrol eder 2. **Remove-LingeringObjects** - Lingering object tespiti ve temizli\u011fi yapar - Advisory mode deste\u011fi - Detayl\u0131 loglama - Her naming context i\u00e7in ayr\u0131 i\u015flem 3. **Get-ADReplicationPerformance** - Performans saya\u00e7lar\u0131n\u0131 izler - CSV format\u0131nda kay\u0131t tutar - \u00d6zet istatistikler olu\u015fturur - \u00c7oklu performans metri\u011fi deste\u011fi 4. **Get-TombstoneLifetime** - Tombstone lifetime de\u011ferini kontrol eder - Warning threshold kontrol\u00fc - Email uyar\u0131 sistemi - Forest genelinde kontrol Her script: - Detayl\u0131 hata yakalama - Loglama - Email bildirimleri - Parametrik yap\u0131land\u0131rma \u00f6zelliklerine sahiptir. Bu scriptleri kullanarak: 1. G\u00fcnl\u00fck replikasyon kontrol\u00fc 2. Haftal\u0131k performans raporu 3. Ayl\u0131k tombstone kontrol\u00fc 4. Gerekti\u011finde lingering object temizli\u011fi &nbsp;","excerpt":"Test-ADReplicationHealth\nRemove-LingeringObjects\nGet-ADReplicationPerformance\nGet-TombstoneLifetime","created_at":"2025-01-27 14:42:57","updated_at":"2026-09-06 23:13:48","category_id":6,"view_count":747,"reading_time":5,"status":"published","editor_choice":0,"is_editor_choice":0,"published_at":"2025-01-27 14:42:57","featured_image":"resimyok.jpg","slug":"active-directory-replikasyon-icin-kullanilacak-scriptler","category_name":"Sistem","category_slug":"sistem"}