Manage the DNS cache on Windows Server

In this “tutorial”, I will give you some PowerShell cmdlets to manage your DNS server cache on Windows Server.

To be more precise, we will see 4 cmdlet PowerShell * -DnsServerCache cmdlets.


The first command displays the DNS cache:


The output of the command gives all DNS records cached on the server.


In console output, it is not necessarily obvious, the capture below was made on a domain controller server and you will notice that there is no cache for the zones managed by the server.

To more easily use the cache, especially if you need to search for a record, it is possible to output the command to a file using> “filename.txt”.

Show-DnsServerCache > dns_cache.txt

Since the output is sent to a file, the command does not return anything to the screen, on the other hand in the folder, I find my file.

The txt file is easier to use when needed:


Now, we will see the command : Clear-DnsServerCache, as its name suggests, it cleans the server’s DNS cache.

This command does not have the same effect as the ipconfig / flushdns command, it acts at the level of the DNS client of the server and not at the level of the DNS server itself.

To purge / clean the DNS server cache enter the command:


Confirm the operation

After confirmation, the command does not return anything, on the other hand you can use the Show-DnsServerCache command to see the result.


This Cmdlet (Get-DnsServerCache) allows you to display the DNS cache configuration on the server:


As we can see, the DNS cache settings on the server are few, there are two particularly interesting settings to configure which are:

  • MaxTTL : which will be the maximum lifetime of a record in the DNS cache
  • MaxKBSize : which is the maximum size of the DNS cache (on the 512MB capture by default 10MB), this parameter is more interesting, because it allows to adjust the size of the cache, for environments with several thousand devices that go on the Internet, it may need to increase this size to reduce DNS queries on Internalt.


The cmdlet Set-DnsServerCache allows you to configure the parameters that are returned with the cmdlet Get-DnsServerCache.

To upgrade the cache to 20MB:

Set-DnsServerCache -MaxKBSize 20480

The command has no particular return, use the Get-DnsServerCache cmdlet, to check the parameters.

Hope this tutorial helps you manage your DNS server cache.

1 thought on “Manage the DNS cache on Windows Server”

Leave a Comment