Let say you want to update the host file particular entry, we have the below host file in our local computer.
# For example: # # 184.108.40.206 rhino.acme.com # source server # 220.127.116.11 x.acme.com # x client host # localhost name resolution is handled within DNS itself. # 127.0.0.1 localhost # ::1 localhost 18.104.22.168 Google.com
We need to update the google.com entry to IP address 22.214.171.124.
$hostfile = "$env:windir\system32\drivers\etc\hosts" $file = Get-Content $hostfile $newfile = $file -replace "126.96.36.199 Google.com","188.8.131.52 Google.com" Set-Content -Value $newfile -Path $hostfile -Force
Once you check the host file again, a new entry will be displayed.
To update the host file on the remote computer, just change the $hostfile variable location and the rest content will be the same.
$hostfile = "\\RemoteServer\C$\Windows\system32\drivers\etc\hosts"