Flush DNS Cache with PowerShell

Flush DNS Cache with PowerShell

A while ago, I wrote a blog post called PowerShell Networking Cheatsheet, where I put together several networking commands which can be replaced by PowerShell. One of the latest once I saw and a couple of people requested is how you flush the DNS cache using PowerShell. This would allow you to replace ipconfig/ flushdns with PowerShell. Guess what, Microsoft as now a PowerShell cmdlet for that.

Clear and Flush DNS with PowerShell

You can use the following command to clear the DNS cache on a Windows system using PowerShell

Clear-DnsClientCache

You can find the documentation for this cmdlet on Microsoft Docs.

Show DNS Cache with PowerShell

There is also a PowerShell command to show you the DNS cache:

Get-DnsClientCache

There are also more cmdlets that can help you to manage your DNS configuration on your Windows machine.

# List DNS servers 
Get-DnsClientServerAddress
 
# Configure a DNS server address using PowerShell 
Set-DnsClientServerAddress
 
# Performs a DNS name query resolution for the specified name.
Resolve-DnsName

Let me know if you have any other helpful cmdlets to manage DNS client settings.

Conclusion

I hope this blog post and these commands to Flush DNS cache with PowerShell are useful. If you have any questions, feel free to leave a comment. If you are interested in PowerShell 7, check out my blog post about how to install and update PowerShell 7 and what’s new in PowerShell 7.