Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ssougnez/62d934241e264c0c7ff622a2e952fd0f to your computer and use it in GitHub Desktop.
Save ssougnez/62d934241e264c0c7ff622a2e952fd0f to your computer and use it in GitHub Desktop.
Function EnsureHostEntry {
Param([string]$ip, [string]$hostName)
$hostFilename = "C:\Windows\System32\drivers\etc\hosts"
[array]$content = [System.IO.File]::ReadAllLines($hostFilename, [System.Text.Encoding]::ASCII) | Select-String $hostName -NotMatch
$content += $("{0}`t`t{1}" -f $ip, $hostName);
[System.IO.File]::WriteAllLines($hostFilename, $content, [System.Text.Encoding]::ASCII)
Success
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment