msenturk
2/24/2016 - 9:50 AM

Update Windows hosts file from https://github.com/StevenBlack/hosts

Update Windows hosts file from https://github.com/StevenBlack/hosts

<#
Tested on Win7-64x and Powershell v5 & v4
maybe Set-ExecutionPolicy Unrestricted
msenturk - 24.02.2016
#>

# Create temp folder..
New-Item -ItemType Directory -Force -Path 'C:\Hosts\'
Set-Location C:\Hosts\
wget 'https://raw.githubusercontent.com/StevenBlack/hosts/master/hosts' -OutFile hosts
# Clean up and remove dublicates ..
Get-Content hosts | Where { $_ -notmatch "\#" } | Where {$_.trim() -ne " " } | Sort-Object -Unique | Set-Content final
# Back-up and Update hostsfile..
Copy-Item -Recurse "C:\Windows\System32\drivers\etc\hosts" -Destination "C:\Windows\System32\drivers\etc\hosts.bak"
Copy-Item -Recurse ".\final" -Destination "C:\Windows\System32\drivers\etc\hosts"
# FlushDNS..
CMD.EXE /C "ipconfig /flushdns" 
Write-Host "`nHosts File Updated" -ForegroundColor Green
rm .\final -Recurse