Purges the cache of a Windows DNS server and then the local client cache as well, so the server itself resolves fresh immediately. The fix for the whole site still seeing an external record that changed hours ago, and it verifies the DNS service is actually running before it tries.
powershell
# Clear DNS Server Cache
# Single use case: purge cached records on a DNS server (stale external record fix)
#-----------------------------------------------------------------
function Write-Log {
param($Message)
Write-Host "<WRITE-LOG = `"*$Message*`">"
}
if (-not (Get-Module -ListAvailable -Name DnsServer)) {
Write-Log "DnsServer module not available - is the DNS role installed on this host?"
return
}
$svc = Get-Service -Name DNS -ErrorAction SilentlyContinue
if ($null -eq $svc -or $svc.Status -ne "Running") {
Write-Log "DNS Server service is not running on this host!"
return
}
Clear-DnsServerCache -Force -ErrorAction SilentlyContinue
Write-Log "DNS server cache cleared."
# Also clear the local client cache so this host resolves fresh immediately
Clear-DnsClientCache -ErrorAction SilentlyContinue
Write-Log "Local DNS client cache cleared as well."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.
More in Windows Server Roles
Report Installed Server Roles with PowerShell
2026-08-17Report DHCP Scope Utilization with PowerShell
2026-08-17Create a DNS A Record with PowerShell
2026-08-17Find the Largest Files in a Folder with PowerShell
2026-08-17Get Folder Sizes with PowerShell
2026-08-17Report SMB Shares and Permissions with PowerShell
2026-08-17Ready when you are.
Try ServerEngine free for 7 days.