<# .SYNOPSIS Active Directory hesabının hangi cihazdan kilitlendiğini bulur. Finds which device locked an Active Directory account. .DESCRIPTION PDC emulator'daki 4740 olaylarından (hesap kilitlendi) kilitleyen cihazı (Caller Computer Name) listeler. Bu alan boşsa, tüm etki alanı denetleyicilerinde aynı kullanıcı için 4771 (Kerberos ön kimlik doğrulaması başarısız) olaylarını tarar ve istemci IP adreslerini gösterir. Lists the locking device (Caller Computer Name) from event 4740 on the PDC emulator. If that field is empty, it scans event 4771 (Kerberos pre-authentication failed) for the same user on every domain controller and shows the client IP addresses. Gereksinimler / Requirements: - ActiveDirectory PowerShell modülü (RSAT) / ActiveDirectory module (RSAT) - Etki alanı denetleyicilerinde güvenlik günlüğünü okuma yetkisi (Event Log Readers) Rights to read the security log on domain controllers (Event Log Readers) - Denetleyicilerde "Remote Event Log Management" güvenlik duvarı kuralı "Remote Event Log Management" firewall rule on the domain controllers Tunbo PRESS — https://press.tunbo.com.tr/araclar — ücretsiz, olduğu gibi sunulur. Free, provided as is. Önce bir test ortamında deneyin / Try it in a test environment first. .PARAMETER UserName Kilitlenen hesabın sAMAccountName değeri. / sAMAccountName of the locked account. .PARAMETER Hours Geriye dönük kaç saatlik olay taranacak (varsayılan 24). / How many hours back to scan (default 24). .EXAMPLE .\Find-LockoutSource.ps1 -UserName ahmet.yilmaz .EXAMPLE .\Find-LockoutSource.ps1 -UserName ahmet.yilmaz -Hours 72 | Export-Csv kilit.csv -NoTypeInformation -Encoding UTF8 #> [CmdletBinding()] param( [Parameter(Mandatory = $true)] [ValidatePattern('^[a-zA-Z0-9._\-]{1,64}$')] [string]$UserName, [ValidateRange(1, 720)] [int]$Hours = 24 ) $ErrorActionPreference = 'Stop' Import-Module ActiveDirectory $pdc = (Get-ADDomain).PDCEmulator $ms = [int64]$Hours * 3600 * 1000 Write-Verbose "PDC emulator: $pdc" # 1) 4740: hesap kilitlendi / account locked out $xpath4740 = "*[System[(EventID=4740) and TimeCreated[timediff(@SystemTime) <= $ms]]] and " + "*[EventData[Data[@Name='TargetUserName']='$UserName']]" $lockouts = @() try { $lockouts = Get-WinEvent -ComputerName $pdc -LogName Security -FilterXPath $xpath4740 -ErrorAction Stop } catch { # Olay yoksa Get-WinEvent hata fırlatır; dilden bağımsız kimlikle ayırt edilir. if ($_.FullyQualifiedErrorId -notmatch 'NoMatchingEventsFound') { throw } } $results = @(foreach ($e in $lockouts) { [pscustomobject]@{ Time = $e.TimeCreated Event = 4740 User = $UserName Source = if ($e.Properties[1].Value) { $e.Properties[1].Value } else { '(boş / empty)' } DomainController = $e.MachineName } }) if (-not $results) { Write-Warning "Son $Hours saatte $UserName için 4740 olayı yok. / No event 4740 for $UserName in the last $Hours hours." } # 2) Kaynak boşsa 4771 ile istemci IP'si / If the source is empty, client IP from 4771 if (-not $results -or ($results | Where-Object { $_.Source -like '(boş*' })) { $xpath4771 = "*[System[(EventID=4771) and TimeCreated[timediff(@SystemTime) <= $ms]]] and " + "*[EventData[Data[@Name='TargetUserName']='$UserName']]" foreach ($dc in (Get-ADDomainController -Filter *).HostName) { try { $events = Get-WinEvent -ComputerName $dc -LogName Security -FilterXPath $xpath4771 -MaxEvents 50 -ErrorAction Stop } catch { if ($_.FullyQualifiedErrorId -notmatch 'NoMatchingEventsFound') { Write-Warning "$dc okunamadı / could not be read: $($_.Exception.Message)" } continue } foreach ($e in $events) { # 4771 veri sırası: TargetUserName, TargetSid, ServiceName, TicketOptions, Status, PreAuthType, IpAddress, IpPort $results += [pscustomobject]@{ Time = $e.TimeCreated Event = 4771 User = $UserName Source = ($e.Properties[6].Value -replace '^::ffff:', '') DomainController = $dc } } } } $results | Sort-Object Time -Descending