Edit the Windows hosts file from the command line
Open the hosts file in Notepad as administrator, or append an entry with Add-Content.
01Command
$ Start-Process notepad "$env:SystemRoot\System32\drivers\etc\hosts" -Verb RunAs02What it does
The hosts file maps domain names to IP addresses before DNS is consulted — handy for testing a new server or blocking a site locally. Because it is a protected system file, it can only be edited by an administrator; the Start-Process -Verb RunAs command opens Notepad elevated after a UAC prompt. To add an entry without opening an editor, run an elevated `Add-Content -Path C:\Windows\System32\drivers\etc\hosts -Value "93.184.216.34 example.com"`.
03Risk
04Undo
$ Remove the added lines from the hosts file to restore default name resolution.05Sources
- Reg - Read and edit the registryEvidence: reg query syntax for reading registry values such as ProxyEnable under HKCU Internet Settings.
- Get-NetConnectionProfileEvidence: Returns the network category (Public/Private/DomainAuthenticated) of each active connection.
Last verified: 2026-09-18 · Category: Network
06Related solutions
Purge cached DNS lookups so Windows re-resolves hostnames from scratch — the fix for 'the new server is live but my browser still hits the old one'.
Diagnose NTFS file system errors and bad sectors on any volume — including the system drive while Windows is running — before committing to a repair.
Robocopy is Windows' built-in robust file copier: use /MIR to keep a destination folder as an exact one-way mirror of a source, resumable and restartable.