Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Updates the Windows HOSTS file for the best protection from scams and unwanted content
- # [Must be run as an Administrator]
- # Version: 1.0B
- # Date Modified: 30/07/17
- # Lists at: https://github.com/StevenBlack/hosts
- $sourceURL = 'https://raw.githubusercontent.com/StevenBlack/hosts/master/alternates/fakenews-social/hosts'
- $hostsFile = "$($env:windir)\system32\Drivers\etc\hosts"
- $outputFile = "$home\Desktop\HOSTS Backups\new-hosts-file.txt"
- $hostsBackupFile = "$home\Desktop\HOSTS Backups\"
- # 1) Backs up current Windows HOSTS File to the Desktop
- Write-Host '1) Backing up Windows HOSTS file...' -ForegroundColor Yellow
- # Create Backup folder
- New-Item -Path $hostsBackupFile -ItemType directory -WarningAction SilentlyContinue -ErrorAction SilentlyContinue
- # Create Backup file
- $hostsBackupFile = $hostsBackupFile+'HOSTS-File-Backup-'+(Get-Date -Format "yyyy-MM-dd\@h-mm-ss")+'.zip'
- Compress-Archive -LiteralPath $hostsFile -CompressionLevel Optimal -DestinationPath $hostsBackupFile
- Write-Host 'Windows HOSTS file backed up.' -ForegroundColor Green
- Write-Host
- # 2) Downloads HOSTS file content
- Write-Host '2) Downloading latest HOSTS file update...' -ForegroundColor Cyan
- $start_time = Get-Date
- (New-Object System.Net.WebClient).DownloadFile($sourceURL, $outputFile)
- Write-Host 'HOSTS file update has been downloaded.' -ForegroundColor Green
- Write-Host "Time taken to download: $((Get-Date).Subtract($start_time).Seconds) second(s)" -ForegroundColor Green
- Write-Host
- # Checks Downloaded File
- if(Test-Path($outputFile))
- {
- # Checks the filesize is larger than 1 MB
- if((Get-Item $outputFile).length -gt 1mb)
- {
- # 3) Replace Windows HOSTS file
- Write-Host '3) Updating Windows HOSTS file with new data...' -ForegroundColor Magenta
- $newHOSTSData = Get-Content -Path $outputFile
- Set-Content -Path $hostsFile -Value $newHOSTSData
- # Clear the DNS
- Clear-DnsClientCache
- $nowDateTime = Get-Date
- Write-Host 'Windows HOSTS has been updated, DNS cache cleared. Process completed at'$nowDateTime -ForegroundColor Green
- }
- }
- # Opens HOSTS file as Administrator
- Start-Process "notepad.exe" -ArgumentList "/W $hostsFile" -Verb runAs
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement