Skip to main content

How to Automatically Flush DNS Weekly on Your VPS

Flushing the DNS cache helps resolve connectivity errors by clearing outdated records from your local system. Instead of doing this manually every week, you can automate it using a simple PowerShell command that creates a scheduled task for you.

Updated this week

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

Did this answer your question?