Skip to main content

Batch script to insert a new entry into the Windows hosts file if doesn't already exist.

set newline=^& echo.

find /C /I "some-host-name.com" %WINDIR%\system32\drivers\etc\hosts
if %ERRORLEVEL% neq 0 echo %newline%^0.0.0.0 some-host-name.com>>%WINDIR%\system32\drivers\etc\hosts