Advertisement
D0cEvil

PowerShell - FinishAddsDnsSetup

Dec 6th, 2022
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PowerShell 1.19 KB | Software | 0 0
  1. ### script made by Michel Belanger###
  2.  
  3. ##get the interfaceindex of ethernet card
  4. $interfaceIndex = Get-NetAdapter -Name ethernet | select -ExpandProperty interfaceindex
  5.  
  6. ##Get the ipv4 address of the ethernet card##
  7. $serverip = Get-NetIPAddress -InterfaceIndex $interfaceIndex | select -ExpandProperty ipv4address
  8.  
  9. ## reset the dns interface set by default after installing adds
  10. Set-dnsclientserveraddress -interfaceindex $interfaceIndex -ResetServerAddresses
  11.  
  12.  
  13. ## set the new dns interface index
  14. Set-dnsclientserveraddress -interfaceindex $interfaceIndex -serveraddresses $serverip
  15.  
  16.  
  17. ##split ip server ipaddress to get the reverse zone##
  18. $splitserver = $serverip.Split(".")
  19.  
  20.  
  21. $Reverse = $splitserver[2] + "." + $splitserver[1] + "." + $splitserver[0] + ".in-addr.arpa"
  22. $ReverseDns = $splitserver[2] + "." + $splitserver[1] + "." + $splitserver[0] + ".in-addr.arpa.dns"
  23. Add-DnsServerPrimaryZone $Reverse -zonefile $ReverseDns
  24.  
  25. ##add ptr record to reverse lookup zone##
  26. $hostname = $env:COMPUTERNAME + "." + (Get-WmiObject win32_computersystem).domain
  27. Add-DnsServerResourceRecordPtr -Name $splitserver[3] -ZoneName $Reverse -AllowUpdateAny -TimeToLive 01:00:00 -AgeRecord -PtrDomainName $hostname
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement