< Back
Get-GCHostsFileEntry
Post
NAME Get-GCHostsFileEntry
SYNOPSIS
Returns any hosts file entries in the form of PSCustomObjects.
SYNTAX
Get-GCHostsFileEntry [[-HostName] <String[]>] [<CommonParameters>]
Get-GCHostsFileEntry [[-IPAddress] <String[]>] [<CommonParameters>]
DESCRIPTION
Reads the contents of the %SYSTEMROOT%\\System32\\drivers\\etc\\hosts file
returning the results as an item or array of PS custom objects.
The returned objects have the following schema:
[PSCustomObject]@{
IPAddress=[IPAddress];
HostNames=[String[]];
Comment=[String];
}
Hosts file single line comments are ignored.
Type 'Get-Help Get-GCHostsFileEntry -Online' for extra information.
PARAMETERS
-HostName <String[]>
Filters the result by host name. Supports a single
host name value or an array of host names.
Required? false
Position? 1
Default value
Accept pipeline input? true (ByValue, ByPropertyName)
Accept wildcard characters? false
-IPAddress <String[]>
Filters the result by host ip address. Supports a single
ip address or an array of ip addresses.
Required? false
Position? 1
Default value
Accept pipeline input? true (ByValue, ByPropertyName)
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.Management.Automation.PSObject[]
-------------------------- EXAMPLE 1 --------------------------
PS C:\\>The following example gets the list of IP addresses in the hosts file
and stores them as strings into the $ip variable:
$entries = Get-GCHostFileEntry
$ip = $entries.IPAddress.IPAddressToString
RELATED LINKS
SYNOPSIS
Returns any hosts file entries in the form of PSCustomObjects.
SYNTAX
Get-GCHostsFileEntry [[-HostName] <String[]>] [<CommonParameters>]
Get-GCHostsFileEntry [[-IPAddress] <String[]>] [<CommonParameters>]
DESCRIPTION
Reads the contents of the %SYSTEMROOT%\\System32\\drivers\\etc\\hosts file
returning the results as an item or array of PS custom objects.
The returned objects have the following schema:
[PSCustomObject]@{
IPAddress=[IPAddress];
HostNames=[String[]];
Comment=[String];
}
Hosts file single line comments are ignored.
Type 'Get-Help Get-GCHostsFileEntry -Online' for extra information.
PARAMETERS
-HostName <String[]>
Filters the result by host name. Supports a single
host name value or an array of host names.
Required? false
Position? 1
Default value
Accept pipeline input? true (ByValue, ByPropertyName)
Accept wildcard characters? false
-IPAddress <String[]>
Filters the result by host ip address. Supports a single
ip address or an array of ip addresses.
Required? false
Position? 1
Default value
Accept pipeline input? true (ByValue, ByPropertyName)
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.Management.Automation.PSObject[]
-------------------------- EXAMPLE 1 --------------------------
PS C:\\>The following example gets the list of IP addresses in the hosts file
and stores them as strings into the $ip variable:
$entries = Get-GCHostFileEntry
$ip = $entries.IPAddress.IPAddressToString
RELATED LINKS