richardszalay / pshosts

PowerShell cmdlets for modifying the hosts file on Windows, Linux, and macOS
MIT License
119 stars 18 forks source link

Add support for profiles/fragments #10

Open richardszalay opened 7 years ago

richardszalay commented 7 years ago

Profiles (essentially "host file fragments") would allow entire blocks of IP addresses to be saved and applied/removed from the system hosts file. Primary use case are swapping entire sets of domains between different environments (or to bypass a load balancer), or simply shipping a set of "dev" host entries along with an application.

Initial thoughts on Cmdlets:

Export-HostsProfile -Hosts @("hosta", "hostb*") -Profile SomeProfile Remove-HostsProfile -Profile SomeProfile - Essentially just Remove-Item on the file Publish-HostsProfile -Profile SomeProfile - Merges a hosts profile into the hosts file, basically calling Set-HostEntry -Force for each of them. Unpublish-HostsProfile -Profile SomeProfile - Removes all host entries specified by a profile (no attempt to restore previous values)

(Profile is either a path to a file or potentially just be a name, in which case it will be stored in Documents\PsHosts\Profiles)

It's probably unnecessary for any of these cmdlets to be C#, since they are all wrapping basic functionality around the core hosts cmdlets.