[CmdletBinding()] param( [ValidateRange(1, 1000)] [int]$Top = 30, [switch]$Flush, [switch]$Force ) $ErrorActionPreference = 'Stop' try { $cache = @(Get-DnsClientCache -ErrorAction Stop) } catch { throw "Не удалось прочитать кэш DNS: $_" } Write-Host ("Записей в кэше: {0}" -f $cache.Count) if ($cache.Count -gt 0) { $cache | Sort-Object Entry | Select-Object -First $Top Entry, RecordName, RecordType, Status, TimeToLive, Data | Format-Table -AutoSize } else { Write-Host 'Кэш DNS пуст.' } if (-not $Flush) { Write-Host 'Это только просмотр. Для сброса добавьте -Flush.' return } if (-not $Force) { $answer = Read-Host 'Введите yes, чтобы очистить кэш DNS' if ($answer -ne 'yes') { Write-Host 'Отменено.' return } } Clear-DnsClientCache -ErrorAction Stop & ipconfig.exe /flushdns | Out-Null Write-Host 'Кэш DNS очищен.'