← script library

Flush the DNS Cache with PowerShell

Self-Healing & RepairAugust 17, 2026

Clears the local resolver cache and reports the entry count before and after, so the run history shows that something was actually flushed. The fix for a host still resolving a record you moved an hour ago, and safe to chain after any DNS change.

powershell
# Flush DNS Client Cache
# Single use case: clear the local DNS resolver cache (stale record fix)
#-----------------------------------------------------------------

function Write-Log {
    param($Message)
    Write-Host "<WRITE-LOG = `"*$Message*`">"
}

$before = (Get-DnsClientCache -ErrorAction SilentlyContinue | Measure-Object).Count
Write-Log "DNS cache entries before flush: $before"

Clear-DnsClientCache -ErrorAction SilentlyContinue

$after = (Get-DnsClientCache -ErrorAction SilentlyContinue | Measure-Object).Count
Write-Log "DNS cache entries after flush: $after"
Write-Log "DNS client cache flushed."

Run it across your fleet

This script runs as-is on a single host. Paste it into ServerEngine to schedule it, run it on a whole server group in parallel, and keep the credentials out of the file — see the scripts documentation and the credential store.

Ready when you are.

Try ServerEngine free for 7 days.