Skip to content

Instantly share code, notes, and snippets.

@kilasuit
Last active February 2, 2022 23:52
Show Gist options
  • Save kilasuit/54b34164fb3588b027eaef4456b938de to your computer and use it in GitHub Desktop.
Save kilasuit/54b34164fb3588b027eaef4456b938de to your computer and use it in GitHub Desktop.
functions for enabling/disabling Website access via hosts file.
#Requires -RunAsAdministrator
#Requires -Module @{ ModuleName = 'PSHosts';
RequiredVersion = '1.2.2' }
Function New-WebSiteHostEntry {
[CmdletBinding()]
[Alias('NWA')]
param (
# Parameter help description
[Parameter()]
[switch]
$SocialMediaSites,
[Parameter()]
[switch]
$NewsSites
)
If($SocialMediaSites) {
"t.co","twitter.com","facebook.com","messenger.com","linkedin.com" | ForEach-Object {Add-HostEntry -Name $_ -Address '0.0.0.0' -Enabled $true -Force}
}
If($NewsSites) {
"bbc.co.uk","vice.com","theguardian.com","msn.com","news.sky.com" | ForEach-Object {Add-HostEntry -Name $_ -Address '0.0.0.0' -Enabled $true -Force}
}
}
function Enable-WebsiteAccess {
[CmdletBinding()]
[Alias('EWA')]
param (
# Parameter help description
[Parameter()]
[switch]
$SocialMediaSites,
[Parameter()]
[switch]
$NewsSites
)
If($SocialMediaSites) {
"t.co","twitter.com","facebook.com","messenger.com","linkedin.com" | ForEach-Object {Get-HostEntry -Name $_ | Disable-HostEntry}
}
If($NewsSites) {
"bbc.co.uk","vice.com","theguardian.com","msn.com","news.sky.com" | ForEach-Object {Get-HostEntry -Name $_ | Disable-HostEntry}
}
}
function Disable-WebsiteAccess {
[CmdletBinding()]
[Alias('DWA')]
param (
# Parameter help description
[Parameter()]
[switch]
$SocialMediaSites,
[Parameter()]
[switch]
$NewsSites
)
If($SocialMediaSites) {
"t.co","twitter.com","facebook.com","messenger.com","linkedin.com" | ForEach-Object {Get-HostEntry -Name $_ | Enable-HostEntry}
}
If($NewsSites) {
"bbc.co.uk","vice.com","theguardian.com","msn.com","news.sky.com" | ForEach-Object {Get-HostEntry -Name $_ | Enable-HostEntry}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment