< Back

Set-GCHostsFileEntry

Mon Jan 13, 2020 8:07 pm

NAME Set-GCHostsFileEntry



SYNOPSIS

Updates an existing hosts file IP address if the host name exists.

If the host name does not exist in the hosts file it will be added.





SYNTAX

Set-GCHostsFileEntry [-IPAddress] <String> [-HostName] <String[]> [[-Comment] <String>] [<CommonParameters>]



Set-GCHostsFileEntry [[-InputObject] <PSObject[]>] [<CommonParameters>]





DESCRIPTION

The hosts file is search to find the host name.

If the host name is found the IP address is updated.

If the host name is not found a new entry will be added

at the bottom of the hosts file.



This cmdlet does not search IP addresses, only host names.

If you wish to update the host name for an IP address use

Remove-GCHostsFileEntry followed by Add-GCHostsFileEntry.



WARNING: If you pipe many thousands of InputObjects into this cmdlet

it will take a long time to process the changes. Be patient.



Type 'Get-Help Set-GCHostsFileEntry -Online' for extra information.





PARAMETERS

-InputObject <PSObject[]>



Required? false

Position? 1

Default value

Accept pipeline input? true (ByValue, ByPropertyName)

Accept wildcard characters? false



-IPAddress <String>

The IP address to assign to the host name.

This can be an IPv4 or IPv6 address.



Required? true

Position? 1

Default value

Accept pipeline input? false

Accept wildcard characters? false



-HostName <String[]>

The name of the host to assign the IP address to.

This can be a fully qualified name such as server1.domain.com, or a flat name.

An array of names is supported.



Required? true

Position? 2

Default value

Accept pipeline input? false

Accept wildcard characters? false



-Comment <String>

Adds a comment on the same line as the IPAddress and HostName pair.



There is no need to supply the '#' character.



Required? false

Position? 3

Default value

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

System.String





-------------------------- EXAMPLE 1 --------------------------



PS C:\\>The following example updates the hosts file entry with a



host name of 'server1.company.com' to have a new IP address

of '5.6.7.8'. If the host name 'server1.company.com' does not

exist in the hosts file it will be added:



Set-GCHostsFileEntry -IPAddress 5.6.7.8 -HostName 'server1.company.com'











RELATED LINKS