PowerShell/scripts/clear-dns-cache.ps1

27 lines
583 B
PowerShell
Raw Normal View History

2024-10-01 15:11:03 +02:00
<#
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
2024-10-02 10:14:17 +02:00
Cleared DNS cache in 1s.
2022-05-09 16:18:05 +02:00
.LINK
https://github.com/fleschutz/PowerShell
.NOTES
Author: Markus Fleschutz | License: CC0
#>
try {
2024-10-02 10:14:17 +02:00
$stopWatch = [system.diagnostics.stopwatch]::startNew()
2022-05-09 16:18:05 +02:00
2022-05-09 16:20:18 +02:00
Clear-DnsClientCache
2022-05-09 16:18:05 +02:00
2024-10-02 10:14:17 +02:00
[int]$elapsed = $stopWatch.Elapsed.TotalSeconds
"✅ Cleared DNS cache in $($elapsed)s."
2022-05-09 16:18:05 +02:00
exit 0 # success
} catch {
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
exit 1
}