< Back
Add-TecBoxHostnames
Post
NAME Add-TecBoxHostnames
SYNOPSIS
Adds one or more hostnames to the hosts file.
SYNTAX
Add-TecBoxHostnames [-IPAddress] <String> [-Hostnames] <String[]> [[-Comment] <String>] [[-RetryCount] <Int32>]
[<CommonParameters>]
DESCRIPTION
The hosts file is used to map hostnames to IP addresses.
PARAMETERS
-IPAddress <String>
The IP address to map the hostname(s) to.
Required? true
Position? 1
Default value
Accept pipeline input? false
Accept wildcard characters? false
-Hostnames <String[]>
One or more hostnames to map to the specified IP address.
Required? true
Position? 2
Default value
Accept pipeline input? true (ByValue)
Accept wildcard characters? false
-Comment <String>
Optional comment that is written above the new hosts entry.
Required? false
Position? 3
Default value
Accept pipeline input? false
Accept wildcard characters? false
-RetryCount <Int32>
How many times to try writing to the hosts file before giving up? Defaults to 30.
IMPORTANT: It's advised to retry as many times as possible to avoid
transient locks on the hosts file causing a failure.
Required? false
Position? 4
Default value 30
Accept pipeline input? false
Accept wildcard characters? false
<CommonParameters>
This cmdlet supports the common parameters: Verbose, Debug,
ErrorAction, ErrorVariable, WarningAction, WarningVariable,
OutBuffer, PipelineVariable, and OutVariable. For more information, see
about_CommonParameters (https:/go.microsoft.com/fwlink/?LinkID=113216).
INPUTS
OUTPUTS
NOTES
This script must be run with administrator privileges.
CRITICAL: The consequence of a failure is the hosts file will be left empty.
TODO: Improvement robustness to prevent a failure resulting in an empty hosts file
-------------------------- EXAMPLE 1 --------------------------
PS C:\\>Add-TecBoxHostnames 127.0.0.1 foobar
Description
-----------
Adds the following line to the hosts file (assuming "foobar" does not already
exist in the hosts file):
127.0.0.1 foobar
A warning is displayed if "foobar" already exists in the hosts file and is
mapped to the specified IP address. An error occurs if "foobar" is already
mapped to a different IP address.
-------------------------- EXAMPLE 2 --------------------------
PS C:\\>Add-TecBoxHostnames 127.0.0.1 foo, bar "This is a comment"
Description
-----------
Adds the following lines to the hosts file (assuming "foo" and "bar" do not
already exist in the hosts file):
# This is a comment
127.0.0.1 foo bar
A warning is displayed if either "foo" or "bar" already exists in the hosts
file and is mapped to the specified IP address. An error occurs if "foo" or
"bar" is already mapped to a different IP address.
RELATED LINKS
SYNOPSIS
Adds one or more hostnames to the hosts file.
SYNTAX
Add-TecBoxHostnames [-IPAddress] <String> [-Hostnames] <String[]> [[-Comment] <String>] [[-RetryCount] <Int32>]
[<CommonParameters>]
DESCRIPTION
The hosts file is used to map hostnames to IP addresses.
PARAMETERS
-IPAddress <String>
The IP address to map the hostname(s) to.
Required? true
Position? 1
Default value
Accept pipeline input? false
Accept wildcard characters? false
-Hostnames <String[]>
One or more hostnames to map to the specified IP address.
Required? true
Position? 2
Default value
Accept pipeline input? true (ByValue)
Accept wildcard characters? false
-Comment <String>
Optional comment that is written above the new hosts entry.
Required? false
Position? 3
Default value
Accept pipeline input? false
Accept wildcard characters? false
-RetryCount <Int32>
How many times to try writing to the hosts file before giving up? Defaults to 30.
IMPORTANT: It's advised to retry as many times as possible to avoid
transient locks on the hosts file causing a failure.
Required? false
Position? 4
Default value 30
Accept pipeline input? false
Accept wildcard characters? false
<CommonParameters>
This cmdlet supports the common parameters: Verbose, Debug,
ErrorAction, ErrorVariable, WarningAction, WarningVariable,
OutBuffer, PipelineVariable, and OutVariable. For more information, see
about_CommonParameters (https:/go.microsoft.com/fwlink/?LinkID=113216).
INPUTS
OUTPUTS
NOTES
This script must be run with administrator privileges.
CRITICAL: The consequence of a failure is the hosts file will be left empty.
TODO: Improvement robustness to prevent a failure resulting in an empty hosts file
-------------------------- EXAMPLE 1 --------------------------
PS C:\\>Add-TecBoxHostnames 127.0.0.1 foobar
Description
-----------
Adds the following line to the hosts file (assuming "foobar" does not already
exist in the hosts file):
127.0.0.1 foobar
A warning is displayed if "foobar" already exists in the hosts file and is
mapped to the specified IP address. An error occurs if "foobar" is already
mapped to a different IP address.
-------------------------- EXAMPLE 2 --------------------------
PS C:\\>Add-TecBoxHostnames 127.0.0.1 foo, bar "This is a comment"
Description
-----------
Adds the following lines to the hosts file (assuming "foo" and "bar" do not
already exist in the hosts file):
# This is a comment
127.0.0.1 foo bar
A warning is displayed if either "foo" or "bar" already exists in the hosts
file and is mapped to the specified IP address. An error occurs if "foo" or
"bar" is already mapped to a different IP address.
RELATED LINKS