-
-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathGet-Hosts.ps1
More file actions
42 lines (39 loc) · 683 Bytes
/
Get-Hosts.ps1
File metadata and controls
42 lines (39 loc) · 683 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<#
.SYNOPSIS
Display the /etc/hosts file
#>
$addresses = (Get-Network -addresses)
$file = "$env:windir\System32\drivers\etc\hosts"
Get-Content $file | % `
{
$i = $_.IndexOf('#')
if ($i -eq 0)
{
Write-Host $_ -ForegroundColor DarkGreen
}
elseif ($i -gt 0)
{
$left = $_.Substring(0, $i - 1)
$addr = $_.Split(' ')
if ($addr.Length -gt 0)
{
if ($addresses.Contains($addr[0]))
{
Write-Host $left -NoNewline -ForegroundColor White
}
else
{
Write-Host $left -NoNewline -ForegroundColor DarkGray
}
}
else
{
Write-Host $left -NoNewline
}
Write-Host ("`t" + $_.Substring($i)) -ForegroundColor DarkCyan
}
else
{
Write-Host $_
}
}