PowerShell/Scripts/clear-dns-cache.ps1

27 lines
590 B
PowerShell
Raw Normal View History

2022-05-09 16:18:05 +02:00
<#
.SYNOPSIS
Clears the DNS cache
.DESCRIPTION
2022-05-09 16:20:18 +02:00
This PowerShell script clears the DNS client cache of the local computer.
2022-05-09 16:18:05 +02:00
.EXAMPLE
2023-08-06 21:35:36 +02:00
PS> ./clear-dns-cache.ps1
2023-09-11 19:28:56 +02:00
Cleared DNS cache in 1 sec
2022-05-09 16:18:05 +02:00
.LINK
https://github.com/fleschutz/PowerShell
.NOTES
Author: Markus Fleschutz | License: CC0
#>
try {
$StopWatch = [system.diagnostics.stopwatch]::startNew()
2022-05-09 16:20:18 +02:00
Clear-DnsClientCache
2022-05-09 16:18:05 +02:00
[int]$Elapsed = $StopWatch.Elapsed.TotalSeconds
2023-09-11 19:28:56 +02:00
"✔️ Cleared DNS cache in $Elapsed sec"
2022-05-09 16:18:05 +02:00
exit 0 # success
} catch {
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
exit 1
}