Ashkynn

DNS Change

Jul 12th, 2021 (edited)
717
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.00 KB | None | 0 0
  1. <#
  2. .Description
  3. This Script contains an function which switches your dns to google.
  4. if you already use google dns is switches to the DHCP distributed dns
  5.  
  6. #>
  7.  
  8.  
  9. # Self-elevate the script if required
  10. if (-Not ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] 'Administrator')) {
  11. if ([int](Get-CimInstance -Class Win32_OperatingSystem | Select-Object -ExpandProperty BuildNumber) -ge 6000) {
  12. $CommandLine = "-File `"" + $MyInvocation.MyCommand.Path + "`" " + $MyInvocation.UnboundArguments
  13. Start-Process -FilePath PowerShell.exe -Verb Runas -ArgumentList $CommandLine
  14.  
  15. }
  16. }
  17.  
  18.  
  19. function WriteOldDns {
  20. Write-Host "Your previous DNS was:"
  21. Get-DnsClientServerAddress -InterfaceAlias "Ethernet"
  22. }
  23.  
  24.  
  25.  
  26. function WriteNewDns {
  27. Write-Host "Your current DNS was:"
  28. Write-Host "
  29. InterfaceAlias Interface Address Server Addressess
  30. Index Family
  31. -------------- --------- ------- -----------------"
  32.  
  33. Get-DnsClientServerAddress -InterfaceAlias "Ethernet"
  34. }
  35.  
  36.  
  37.  
  38. function setDnsToGoogle
  39. {
  40. param
  41. (
  42. $interfacealias = "Ethernet"
  43. )
  44. $googleIP = @("8.8.8.8","8.8.4.4","2001:4860:4860::8888","2001:4860:4860::8844")
  45. $currentdns = Get-DnsClientServerAddress -InterfaceAlias $interfacealias
  46. foreach ($gip in $googleIP)
  47. {
  48. if(($currentdns).ServerAddresses -like $gip)
  49. {
  50. Set-DnsClientServerAddress -InterfaceAlias $interfacealias -ResetServerAddresses
  51. Clear-DnsClientCache
  52.  
  53. }else
  54. {
  55. Set-DnsClientServerAddress -InterfaceAlias $interfacealias -ServerAddresses ("8.8.8.8","8.8.4.4","2001:4860:4860::8888","2001:4860:4860::8844")
  56.  
  57. }
  58. }
  59.  
  60.  
  61. }
  62.  
  63.  
  64.  
  65.  
  66. WriteOldDns
  67.  
  68. setDnsToGoogle
  69.  
  70. Write-Host "
  71.  
  72. "
  73.  
  74. WriteNewDns
  75.  
  76. Start-Sleep -Seconds 10
  77. Pause
  78.  
Add Comment
Please, Sign In to add comment