-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathOpen-GCHostsFile.ps1
30 lines (29 loc) · 1.02 KB
/
Open-GCHostsFile.ps1
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
<#
.SYNOPSIS
Opens the %SYSTEMROOT%\System32\drivers\etc\hosts file in notpade.exe.
.DESCRIPTION
A warning is displayed requiring you to press enter if the
PowerShell console is not running As Administrator.
Type 'Get-Help Open-GCHostsFile -Online' for extra information.
.PARAMETER Force
Prevents both the display of the As Administrator console warning
and the requirement to press enter.
#>
function Open-GCHostsFile {
[CmdletBinding(HelpUri = 'https://github.com/grantcarthew/ps-gcpowershell')]
[Alias()]
[OutputType([String])]
Param (
[Parameter(Mandatory=$false,
Position=0)]
[Switch]
$Force
)
Import-Module -Name GCTest
$hostsFilePath = Join-Path -Path $env:SystemRoot -ChildPath '\System32\drivers\etc\hosts'
if (-not (Test-GCFileWrite $hostsFilePath) -and -not $Force) {
Write-Warning -Message "The PowerShell session does not have write access to the hosts file. Changes will not be saved."
Pause
}
Start-Process -FilePath 'notepad.exe' -ArgumentList $hostsFilePath
}