Remove-HostsEntry

Removes entries from the hosts file by hostname.

Syntax

Remove-HostsEntry [-HostName] <String[]> [-Path <String>] [-WhatIf] [-Confirm] [<CommonParameters>]

Description

You can remove multiple entries or pipe entries into this function.

Parameters

Name Type Description Required? Pipeline Input Default Value
HostName String[]

The hostname of the hosts entry/entries to remove.

true true (ByValue)
Path String

The hosts file to modify. Defaults to the Windows hosts file.

false false (Get-PathToHostsFile)
WhatIf SwitchParameter false false
Confirm SwitchParameter false false
CommonParameters This cmdlet supports common parameters. For more information type
Get-Help about_CommonParameters.

EXAMPLE 1

Remove-HostsEntry -HostName 'adadvisor.net'

Demonstrates how to remove hosts entry for adadvisor.net, which you probably don't want to do.

EXAMPLE 2

Remove-HostsEntry -HostName 'adadvisor.net','www.adchimp.com'

Demonstrates how to remove multiple hosts entries.

EXAMPLE 3

('adadvisor.net','www.adchimp.com') | Remove-HostsEntry

Demonstrates how to pipe hostnames into Remove-HostsEntry.

EXAMPLE 4

Remove-HostsEntry -HostName 'adadvisor.net' -Path 'C:\Projects\Carbon\adblockhosts'

Demonstrates how to work with a file other than Windows' default hosts file.