-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUpdateHosts.ps1
More file actions
16 lines (14 loc) · 765 Bytes
/
Copy pathUpdateHosts.ps1
File metadata and controls
16 lines (14 loc) · 765 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# This script creates a backup of the original hosts file (excluding lines not starting with "#")
# in a file called "OldHost"
# It then adds a new line to the hosts file and saves the changes.
# Enter the new line inside the " " below
# Example:
# $NewLine = "192.168.1.201 SERVER03"
$NewLine = " "
$file = "C:\Windows\System32\drivers\etc\hosts"
$hostfile = Get-Content $file
$linesToCopy = $hostfile | Where-Object { $_ -notmatch '^#' } # Select lines that don't start with "#"
$linesToCopy | Out-File -FilePath "C:\Windows\System32\drivers\etc\OldHost" -Append # Copy lines to OldHost file
$hostfile = $hostfile | Where-Object { $_ -match '^#' } # Remove lines that don't start with "#"
$hostfile += $NewLine
$hostfile | Set-Content -Path $file -Force