Let say you want to update the host file particular entry, we have the below host file in our local computer.
# For example: # # 126.96.36.199 rhino.acme.com # source server # 188.8.131.52 x.acme.com # x client host # localhost name resolution is handled within DNS itself. # 127.0.0.1 localhost # ::1 localhost 184.108.40.206 Google.com
We need to update the google.com entry to IP address 220.127.116.11.
$hostfile = "$env:windir\system32\drivers\etc\hosts" $file = Get-Content $hostfile $newfile = $file -replace "18.104.22.168 Google.com","22.214.171.124 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"