PowerShell cmdlets for modifying the hosts file on Windows, Linux, and macOS
MIT License
PsHosts is a PowerShell Module that provides Cmdlets for manipulating the local hosts file on Windows, Linux, and macOS. Supports tab completion for hostnames.
All destructive commands support -whatif
and honor original formatting wherever possible.
Windows 10, Linux, and macOS users can simply install the module using the command below. For Windows 8.1 and below, PsGet can be used with the same command.
PS C:\> Install-Module PsHosts
To install manually, download a release and unzip to $home\Documents\WindowsPowerShell\Modules\PsHosts
The Cmdlets use the noun HostEntry
and support the following verbs:
General things to remember:
-whatif
With that in mind, here are some samples:
# List all entries
Get-HostEntry
# List matching entries
Get-HostEntry *.local
Get-HostEntry mysite.local
# Test if an entry exists
Test-HostEntry mysite.local
# Add a localhost entry
Add-HostEntry mysite.local -Loopback
# Add a specific entry
Add-HostEntry mysite.local 192.168.1.1
# Change an entry's IP address
Set-HostEntry mysite.local 127.0.0.2
# Add a comment
Set-HostEntry mysite.local -Comment Excellent
# Rename a host
Get-HostEntry mysite.local | Set-HostEntry mysite2.local
# Disable (comment out) entries
Disable-HostEntry mysite.local
# Enable (uncomment) entries
Enable-HostEntry mysite.local
# Remove entries
Remove-HostEntry mysite.local
# Remove matching entries
Remove-HostEntry *.local
# Disable all loopback entries
Get-HostEntry | ?{$_.IsLoopback} | Disable-HostEntry
OS - PS Version | Build Status |
---|---|
AppVeyor (Windows - PS 5.1) | |
Travis CI (Linux - PS 6.0.0-Beta) | |
Travis CI (MacOS - PS 6.0.0-Beta) |
Building is supported on all platforms with PowerShell.
PsHosts uses Invoke-Build for build automation. Tests can be run by running the following from the root of the repository:
.\build.ps1 -Test
The solution is made up of a number of projects: