Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.