This is redacted version of a powershell script I had to come up with recently to fix an issue with a web application in our environment.

1
2
3
4
5
6
7
8
$hostsPath = "$env:windir\System32\drivers\etc\hosts"
$ip = ipconfig | findstr /i IPv4 |Out-string
$ip = $ip.TrimStart("IPv4 Address. . . . . . . . . . . : ")
$ip = $ip.TrimEnd("`n")
$ip = $ip.TrimEnd("`r")
Clear-Content $hostsPath
ipconfig /flushdns
Add-Content $hostsPath "$ip siteurl.com"

I will walk through what is going on here…
(more…)