Edit Network “hosts” File

by Aug 5, 2014

All PowerShell versions

If you find yourself editing the “hosts” file regularly, then it may be tedious to manually open the file in an elevated instance of the Notepad. Since this file can only be edited by Administrators, a normal Notepad instance won’t do.

Here is some code that you can use as-is or easily adjust to open any program with elevated privileges.

function Show-HostsFile
{
  $Path = "$env:windir\system32\drivers\etc\hosts"
  Start-Process -FilePath notepad -ArgumentList $Path -Verb runas
}

Twitter This Tip! ReTweet this Tip!