Add clear-dns-cache.ps1

This commit is contained in:
Markus Fleschutz
2022-05-09 16:18:05 +02:00
parent 7b46ee3503
commit 546c436b3e
2 changed files with 30 additions and 0 deletions

View File

@ -0,0 +1,26 @@
<#
.SYNOPSIS
Clears the DNS cache
.DESCRIPTION
This PowerShell script clears the DNS cache of the local computer.
.EXAMPLE
PS> ./clear-dns-cache
.LINK
https://github.com/fleschutz/PowerShell
.NOTES
Author: Markus Fleschutz | License: CC0
#>
try {
$StopWatch = [system.diagnostics.stopwatch]::startNew()
$null = (ipconfig /flushdns)
if ($lastExitCode -ne "0") { throw "'ipconfig /flushdns' failed with exit code $lastExitCode" }
[int]$Elapsed = $StopWatch.Elapsed.TotalSeconds
"✔️ cleared DNS cache in $Elapsed ms."
exit 0 # success
} catch {
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
exit 1
}