SHARE
TWEET

Untitled

a guest Oct 14th, 2019 77 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Function Create-DNSScavengingRecordsReport
  2. {
  3.     <#The script checks any Dynamic DNS Record and decided whether it’s:
  4.         1)A stale record which responded to ping.
  5.         2)stale record which doesn’t responded to ping.
  6.         3)An updated record (not stale).#>
  7.     $DC = (Get-ADDomainController).Name
  8.     $DNSRoot = (Get-ADDomain).DNSRoot
  9.     $DNSRecords = Get-DnsServerResourceRecord -ComputerName $DC -ZoneName $DNSRoot
  10.     $DateThershold = (Get-Date).AddDays(-14)
  11.     $DNSArray = @()
  12.     ForEach ($DNSRecord in $DNSRecords)
  13.     {
  14.         If ($DNSRecord.RecordType -eq "A" -and $DNSRecord.Timestamp -ne $Null -and $DNSRecord.Hostname -ne "@" -and $DNSRecord.HostName -ne "DomainDnsZones" -and $DNSRecord.HostName -ne "ForestDnsZones")
  15.         {
  16.             $Computer = $DNSRecord.HostName
  17.             $ComputerIP = $DNSRecord.RecordData.IPv4Address.IPAddressToString
  18.             $ComputerOS = "Null"
  19.             Try
  20.             {
  21.                 $ADComputer = Get-ADComputer $Computer -Properties OperatingSystem -ErrorAction Stop
  22.                 $ComputerOS = $ADComputer.OperatingSystem
  23.             }
  24.             Catch
  25.             {
  26.                 Write-Host "The computer object could not be retreived from Active Directory. Skip." -ForegroundColor yellow
  27.             }
  28.             $Ping = Test-Connection -ComputerName $DNSRecord.HostName -Count 1 -ErrorAction SilentlyContinue
  29.             $DNSObject = New-Object -TypeName PSObject
  30.             Add-Member -InputObject $DNSObject -MemberType 'NoteProperty' -Name 'Hostname' -Value $Computer
  31.             Add-Member -InputObject $DNSObject -MemberType 'NoteProperty' -Name 'IP' -Value $ComputerIP
  32.             Add-Member -InputObject $DNSObject -MemberType 'NoteProperty' -Name 'Timestamp' -Value $DNSRecord.Timestamp
  33.             Add-Member -InputObject $DNSObject -MemberType 'NoteProperty' -Name 'OS' -Value $ComputerOS
  34.             If (($DNSRecord.Timestamp) -lt $DateThershold)
  35.             {
  36.                 If ($Ping)
  37.                 {
  38.                     $Status = "Stale record, responding to ping"
  39.                 }
  40.                 Else
  41.                 {
  42.                     $Status = "Stale record, NOT responding to ping"
  43.                 }
  44.             }
  45.             Else
  46.             {
  47.                  $Status = "Updated record"
  48.             }
  49.             Add-Member -InputObject $DNSObject -MemberType 'NoteProperty' -Name 'Status' -Value $Status
  50.             $DNSArray += $DNSObject
  51.         }
  52.     }
  53.     $DNSArray | Out-GridView -Title "DNS Records - Stale Report for $DNSRoot Zone (Querying $DC DNS Server)"
  54. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top