• Stars
    star
    118
  • Rank 292,793 (Top 6 %)
  • Language
    C#
  • License
    MIT License
  • Created over 10 years ago
  • Updated over 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

PowerShell cmdlets for modifying the hosts file on Windows, Linux, and macOS

PsHosts

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.

PsHosts in action

Installation

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

Usage

The Cmdlets use the noun HostEntry and support the following verbs:

  • Get
  • Test
  • Add
  • Set
  • Remove
  • Enable
  • Disable

General things to remember:

  • All destructive Cmdlets require admin elevation
  • The first parameter is always the hostname, which supports tab completion
  • All Cmdlets support pipelining
  • All destructive Cmdlets support -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

Build Status

Master branch

OS - PS Version Build Status
AppVeyor (Windows - PS 5.1) m-av-image
Travis CI (Linux - PS 6.0.0-Beta) m-tv-image
Travis CI (MacOS - PS 6.0.0-Beta) m-tv-image

Development

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:

  • RichardSzalay.Hosts - .NET Library containing core API for manipulating the hosts file
  • RichardSzalay.Hosts.Tests - Unit tests for core API using Machine.Specifications (Mspec)
  • RichardSzalay.Hosts.Powershell - PowerShell Cmdlets library (.NET)
  • RichardSzalay.Hosts.Powershell.Tests - Pester tests for the PowerShell Cmdlets

More Repositories

1

mockhttp

Testing layer for Microsoft's HttpClient library. Create canned responses using a fluent API.
C#
1,557
star
2

raix

raix (Reactive And Interactive eXtensions) is a functional, composable, API for AS3 that simplifies working with data, regardless of whether its interactive (arrays) or reactive (events). raix was previously RxAs
ActionScript
90
star
3

helix-publishing-pipeline

Unified publishing for Sitecore Helix solutions that extends existing Visual Studio and command line workflows
PowerShell
68
star
4

fastlane-plugin-act

Modify plists and app icons inside xcarchives/IPAs. Publish multiple iOS configurations without recompiling
Ruby
36
star
5

iishosts

Provides local hosts file management from within IIS 7+, including bulk editing.
C#
12
star
6

msdeploy-package-publish

Adds MSBuild targets to Web Deploy to support publishing packages
10
star
7

buggy-bits-core

Debugging labs for .NET Core
C#
6
star
8

webdeploy-windows-service

Extension for Microsoft Web Deploy (MSDeploy) that adds support for deploying Windows Services
C#
6
star
9

sitecore-web-config

Comparisons of stock Web.config files from various Sitecore versions to assist with upgrades
PowerShell
6
star
10

spare-keys

Create temporary macOS keychains for CI environments
Ruby
5
star
11

semantic-logging-sentry

Sentry sink for Semantic Logging
C#
4
star
12

sitecore-azure-search-compat

Compatibility patch for Sitecore + Azure Search
C#
3
star
13

sitecore-commerce-configuration

Tools for configuring and boostrapping Sitecore Commerce Engine configuration
PowerShell
3
star
14

phone-common-strings

A set of string resources commonly used by Windows Phone applications, localized into all languages supported by the platform.
C#
2
star
15

rainbow-webpack-plugin

Output assets in Unicorn's Rainbow (yml) format for use with transparent sync
TypeScript
2
star
16

sitecore-icon-build

MSBuild support for building Sitecore icon archives
PowerShell
1
star
17

sitecore-assembly-lists

Tools for generating and validating Sitecore assembly lists
PowerShell
1
star
18

wp-themeresourcedictionary

Declarative support for light/dark themes on WP7
1
star