Created
April 4, 2010 22:15
-
-
Save johnnyhalife/355746 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Adds a new host entry on the hosts file as shown: | |
# | |
# add-host www.southworks.net 127.0.0.1 [optional $true|$false] | |
# | |
# the third parameter indicates whether if exists it should be overwritten | |
function add-host { | |
# map parameters | |
$hostname, $address, $override = $args[0], $args[1], ($args[2] -eq $true) | |
# generte some basics | |
$hosts, $entry = (gc hosts), "$hostname $address" | |
if([regex]::match($hosts, "\s*$hostname\s*").success){ | |
# it already existed but chose not override | |
if(-not $override) { return; } | |
clear-content hosts | |
$hosts | where-object{[regex]::match($_, "\s*$hostname\s.*$").success -eq $false} | add-content hosts | |
} | |
# now append it | |
add-content hosts $entry | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment