InterspaceKnowledgebaseTech ArticlesTutorialsEnable Standard Users in Windows Server to Clear DNS Cache
TUTORIALS
16-Dec-2024
Enable Standard Users in Windows Server to Clear DNS Cache
The DNS cache in Windows systems is usually cleared with the command ipconfig /flushdns. This command requires administrative privileges, which creates a challenge in Windows Server environments where standard users need to refresh their DNS cache during troubleshooting or after network changes.

To work around this limitation, we'll create an automated system that consists of:

  • One-time setup by the Administrator. A user with Administrator privileges creates and executes a PowerShell script, which runs continuously in the background with administrative privileges. Its sole purpose is to monitor a designated folder for any changes. When changes are detected, it executes the DNS flush command automatically.
  • Standard User Operation. To clear the DNS cache, a standard user creates an empty file or folder in the monitored folder. The file or folder will disappear in about 10 seconds, indicating that the ipconfig /flushdns command has been executed.

This system maintains security by keeping administrative privileges within the PowerShell script, while standard users only perform file operations in a designated folder where they have been granted access rights.

1.Installation Steps Conducted by the Administrator

The following steps should be performed by a user with Administrator privileges. In this example, we'll use the C: drive, but you can adjust the folder path as needed.

1.1.Create the Monitored Folder

Create a folder named flushdns that will be used for triggering the DNS cache clearing. Grant access to the folder for standard users, typically in the group "Users." Use the following PowerShell commands:
New-Item -Path "C:\flushdns" -ItemType Directory
icacls "C:\flushdns" /grant "Users:(OI)(CI)F"

The second command grants full access to all users. To restrict access to specific users or groups, replace "Users" with the appropriate user or group name.

1.2.Create the PowerShell Script

Create a PowerShell script file at C:\scriptflushdns.ps1 with the following content:
# Path to the folder to monitor
$folderPath = "C:\flushdns"

###### DO NOT MODIFY BELOW THIS LINE
# Window title
$host.UI.RawUI.WindowTitle = "DNS Flush Process"
# Continuous loop
while ($true) {

$files = Get-ChildItem -Path $folderPath -File -ErrorAction SilentlyContinue

# If there are files
if ($files.Count -gt 0) {
# Execute ipconfig /flushdns
try {
$result = Start-Process "ipconfig.exe" -ArgumentList "/flushdns" -Verb RunAs -WindowStyle Hidden -Wait -PassThru
if ($result.ExitCode -ne 0) {
Write-Host "Error: DNS flush failed with code $($result.ExitCode)" -ForegroundColor Red
} else {
Write-Host "DNS cache successfully cleared at $(Get-Date)" -ForegroundColor Green
}
}
catch {
Write-Host "Error executing ipconfig: $($_.Exception.Message)" -ForegroundColor Red
}

# Delete all files
try {
Remove-Item -Path "$folderPath\*" -Force
}
catch {
Write-Host "Error deleting files: $($_.Exception.Message)" -ForegroundColor Red
}
}

# 10 seconds pause between checks
Start-Sleep -Seconds 10
}

1.3.Run the Script

As an Administrator, run C:\scriptflushdns.ps1. This will open a PowerShell console window named "DNS Flush Process." Do not close this window, as the script runs continuously, monitoring the folder and executing the DNS cache clearing when triggered.

Whenever a DNS cache is cleared, the script prints the message: DNS cache successfully cleared at ...

For automatic startup after system reboots, configure the script to run as a scheduled task.

2.Clear the DNS Cache as a Standard User

To clear the DNS cache as a standard Windows user, create an empty file or folder in C:\flushdns.

After about 10 seconds, the created file or folder will disappear, indicating that the ipconfig.exe /flushdns command has been executed.
The content of this document is licensed by Interspace under the MIT License

Related content
Documentation
Cloud
Communications
Hosting
My Interspace
Tech Articles
Tutorials
Learn
News
Latest news
Latest events
Related products
Premium Internet Access
Highest-grade Internet access for professional needs. Superior point-to-point fiber-optic link, symmetrical down/up speed, unlimited traffic, SLA 99.9% and static IP. Direct connections to the top tier 1 global providers. Our network architecture is passionately designed to ensure the highest quality connections to any destination worldwide, boasting unmatched transfer speeds and multi-tier redundancy.
Dedicated Servers
Dedicated servers on high-grade hardware from well-known sever vendors. They are hosted in our own data centers, enabling us full control in safe-guarding the uptime 24/7. Selection of primary data centers and a disaster recovery one located at a safe distance. Power control options (reset, power off/on) and free of charge KVM-over-IP available 24/7 on a single click, including support to remotely boot/install your own ISO images.
Elastic Cloud VPS
Elastic Cloud VPS is a virtual machine powered by advanced cloud and networking technologies, offering significant advantages over traditional VPS hosting at an unbeatable price to performance ratio. Deploy OS and apps in just 1 min. Dynamically add or remove features. One click automatic backups, snapshots and disaster recovery replica, stored in a remote data center at a safe distance. New gen of AMD EPYC CPUs, ultra fast NVMe disks, dedicated connections and free private net.


Our website uses cookies. By continuing to use our website, you consent to the use of cookies and you agree with our Terms and conditions.    I understand