# PowerShell script that can add ad-blocking DNS entries to the Windows hosts file # This script defines the path to the Windows hosts file and a list of ad-blocking DNS entries. # It then reads the contents of the hosts file and adds the ad-blocking DNS entries to it if they are not already # present. # Make sure to run this script with administrative privileges, as modifying the hosts file requires elevated permissions. ```powershell # Define the path to the hosts file $hostsFilePath = "$env:windir\System32\drivers\etc\hosts" # Define the ad-blocking DNS entries $adBlockingDnsEntries = @( "0.0.0.0 ad.doubleclick.net", "0.0.0.0 ads.yahoo.com", "0.0.0.0 googleadservices.com", "0.0.0.0 pagead2.googlesyndication.com", "0.0.0.0 pubads.g.doubleclick.net", "0.0.0.0 securepubads.g.doubleclick.net", "0.0.0.0 www.googleadservices.com", "127.0.0.1 aax-us-east.amazon-adsystem.com", "127.0.0.1 aax-us-west.amazon-adsystem.com", "127.0.0.1 aax-eu.amazon-adsystem.com" ) # Read the contents of the hosts file $hostsFileContents = Get-Content $hostsFilePath # Add the ad-blocking DNS entries to the hosts file $adBlockingDnsEntries | ForEach-Object { if ($hostsFileContents -notcontains $_) { Add-Content $hostsFilePath $_ } } ```