Giter Club home page Giter Club logo

pshosts's Introduction

PsHosts

.NET Library and Powershell Cmdlet Module that adds an API around modifying the hosts file on Windows. Supports tab completion for hostnames.

All destructive commands support -whatif and honor original formatting wherever possible.

PsHosts in action

Installation

Windows 10 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
  • 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

# Add an entry
Add-HostEntry mysite.local 127.0.0.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 | ?{$_.Address -eq "127.0.0.1"} | Disable-HostEntry

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.