# .SYNOPSIS Parolası yakında dolacak Active Directory kullanıcılarını listeler; isterseniz e-postayla gönderir. Lists Active Directory users whose password expires soon; optionally emails the list. .DESCRIPTION msDS-UserPasswordExpiryTimeComputed alanını kullanır; bu alan varsayılan etki alanı politikası ile Fine-Grained Password Policy'yi (FGPP) hesaba katar. Parolası hiç dolmayan ve devre dışı hesaplar hariç tutulur. Uses msDS-UserPasswordExpiryTimeComputed, which accounts for the default domain policy and Fine-Grained Password Policies (FGPP). Accounts whose password never expires and disabled accounts are excluded. Günlük çalıştırmak için Görev Zamanlayıcı'ya ekleyin. / Add to Task Scheduler to run daily. 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 Days Kaç gün içinde dolacak parolalar listelensin (varsayılan 14). / Expiry window in days (default 14). .PARAMETER SearchBase Yalnızca bu OU altındaki kullanıcılar (isteğe bağlı). / Only users under this OU (optional). .PARAMETER CsvPath Sonucun yazılacağı CSV dosyası (isteğe bağlı). / CSV file to write the result to (optional). .PARAMETER MailTo, MailFrom, SmtpServer, SmtpPort, UseSsl Listeyi BT ekibine e-postayla göndermek için (isteğe bağlı). / To email the list to IT (optional). .EXAMPLE .\Get-PasswordExpiryReport.ps1 -Days 7 .EXAMPLE .\Get-PasswordExpiryReport.ps1 -Days 14 -SearchBase "OU=Personel,DC=kurum,DC=local" -CsvPath .\parola-bitis.csv .EXAMPLE .\Get-PasswordExpiryReport.ps1 -Days 7 -MailTo bt@kurum.com.tr -MailFrom press@kurum.com.tr -SmtpServer mail.kurum.com.tr -SmtpPort 587 -UseSsl #> [CmdletBinding()] param( [ValidateRange(1, 365)][int]$Days = 14, [string]$SearchBase, [string]$CsvPath, [string]$MailTo, [string]$MailFrom, [string]$SmtpServer, [int]$SmtpPort = 25, [switch]$UseSsl, [pscredential]$SmtpCredential ) $ErrorActionPreference = 'Stop' Import-Module ActiveDirectory $now = Get-Date $limit = $now.AddDays($Days) $params = @{ Filter = 'Enabled -eq $true -and PasswordNeverExpires -eq $false' Properties = @('msDS-UserPasswordExpiryTimeComputed', 'PasswordLastSet', 'mail', 'DisplayName') } if ($SearchBase) { $params.SearchBase = $SearchBase } $report = Get-ADUser @params | Where-Object { $_.'msDS-UserPasswordExpiryTimeComputed' -gt 0 -and $_.'msDS-UserPasswordExpiryTimeComputed' -lt [int64]::MaxValue } | ForEach-Object { $expires = [datetime]::FromFileTime($_.'msDS-UserPasswordExpiryTimeComputed') [pscustomobject]@{ SamAccountName = $_.SamAccountName DisplayName = $_.DisplayName Mail = $_.mail PasswordLastSet = $_.PasswordLastSet Expires = $expires DaysLeft = [math]::Floor(($expires - $now).TotalDays) } } | Where-Object { $_.Expires -ge $now -and $_.Expires -le $limit } | Sort-Object Expires if ($CsvPath) { $report | Export-Csv -Path $CsvPath -NoTypeInformation -Encoding UTF8 Write-Host "CSV: $CsvPath ($(@($report).Count) kullanıcı / users)" } if ($MailTo) { if (-not $MailFrom -or -not $SmtpServer) { throw "-MailTo için -MailFrom ve -SmtpServer gerekli. / -MailTo requires -MailFrom and -SmtpServer." } $rows = ($report | ForEach-Object { "
Parolası $Days gün içinde dolacak kullanıcılar / Users whose password expires within $Days days: $(@($report).Count)
" + "| Kullanıcı / User | Ad / Name | Bitiş / Expires | Gün / Days |
|---|
Get-PasswordExpiryReport.ps1 — Tunbo PRESS
" $mail = @{ To = $MailTo; From = $MailFrom; SmtpServer = $SmtpServer; Port = $SmtpPort Subject = "Parolası $Days gün içinde dolacak kullanıcılar: $(@($report).Count)" Body = $body; BodyAsHtml = $true; Encoding = [System.Text.Encoding]::UTF8 } if ($UseSsl) { $mail.UseSsl = $true } if ($SmtpCredential) { $mail.Credential = $SmtpCredential } # Send-MailMessage Microsoft tarafından eski kabul edilir ama Windows PowerShell 5.1'de çalışır. Send-MailMessage @mail Write-Host "E-posta gönderildi / Email sent: $MailTo" } $report