Skip to main content

How to Automatically Flush DNS Weekly on Your VPS

Automate a weekly DNS flush on your VPS with a scheduled PowerShell task to prevent stale-DNS connection errors.

Stale DNS entries can cause connection errors over time. This guide sets up a scheduled task on your VPS that flushes the DNS cache automatically every week — no ongoing maintenance required.

This task will:

  • Run every Saturday at 3:00 AM

  • Flush the DNS cache automatically

  • Run silently in the background (no pop-ups)

  • Require no further maintenance after setup


Step #1: Open PowerShell as Administrator

  1. Click Start → type PowerShell

  2. Right-click Windows PowerShell → choose Run as Administrator


Step #2: Copy & Paste the Script Below

Copy the entire script below and paste it directly into the PowerShell window.

Then press Enter once.

$TaskName  = "FlushDNS-Weekly"
$Action = New-ScheduledTaskAction -Execute 'powershell.exe' `
-Argument '-NoProfile -WindowStyle Hidden -Command "Clear-DnsClientCache; ipconfig /flushdns | Out-Null"'
$Trigger = New-ScheduledTaskTrigger -Weekly -DaysOfWeek Saturday -At 03:00
$Principal = New-ScheduledTaskPrincipal -UserId "SYSTEM" -LogonType ServiceAccount -RunLevel Highest

if (Get-ScheduledTask -TaskName $TaskName -ErrorAction SilentlyContinue) {
Unregister-ScheduledTask -TaskName $TaskName -Confirm:$false
}

Register-ScheduledTask -TaskName $TaskName -Action $Action -Trigger $Trigger -Principal $Principal `
-Description "Flushes DNS cache weekly (every Saturday at 3:00 AM)" | Out-Null

Write-Host "Scheduled task '$TaskName' created successfully."
Write-Host "It will run every Saturday at 3:00 AM and silently flush the DNS cache."

Once you press Enter, the task will be created automatically.


Step #3: (Optional) Verify or Test the Task

You can confirm it's active or run it immediately:

Action

PowerShell Command

View the task

Get-ScheduledTask -TaskName "FlushDNS-Weekly"

Run it manually

Start-ScheduledTask -TaskName "FlushDNS-Weekly"

Check next run time

Get-ScheduledTaskInfo -TaskName "FlushDNS-Weekly" | Select LastRunTime, NextRunTime


Step #4: You're Done!

Your VPS will now flush the DNS cache automatically every Saturday at 3:00 AM.

No additional steps or logins are needed — it runs silently under the system account.

If you ever wish to remove it, run this command:

Unregister-ScheduledTask -TaskName "FlushDNS-Weekly" -Confirm:$false

Need Assistance?

Our support team is available 24/7. If you have any questions or run into issues, open a support ticket from your QuantVPS dashboard and we'll get back to you as quickly as possible.

Did this answer your question?