PowerShell/scripts/clear-dns-cache.ps1
2024-10-02 10:14:17 +02:00

27 lines
583 B
PowerShell
Executable File

<#
.SYNOPSIS
Clears the DNS cache
.DESCRIPTION
This PowerShell script clears the DNS client cache of the local computer.
.EXAMPLE
PS> ./clear-dns-cache.ps1
✅ Cleared DNS cache in 1s.
.LINK
https://github.com/fleschutz/PowerShell
.NOTES
Author: Markus Fleschutz | License: CC0
#>
try {
$stopWatch = [system.diagnostics.stopwatch]::startNew()
Clear-DnsClientCache
[int]$elapsed = $stopWatch.Elapsed.TotalSeconds
"✅ Cleared DNS cache in $($elapsed)s."
exit 0 # success
} catch {
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
exit 1
}