Thursday, 12 August 2010

Get-DnsRegisteredServers.ps1

  1. <# 
  2. .SYNOPSIS 
  3.     This script gets the reverse lookup zone from a DNS Server and 
  4.     displays all the systems registered 
  5. .DESCRIPTION 
  6.     This script first gets the reverse lookup zone from a DNS Server (i.e. 
  7.     all the computers that have used the DNS server to register!). The 
  8.     script then displays the FQDN, IP Address and Timestamp. 
  9. .NOTES 
  10.     File Name  : Get-DnsRegisteredServers.ps1 
  11.     Author     : Thomas Lee - tfl@psp.co.uk 
  12.     Requires   : PowerShell Version 2.0 
  13. .LINK 
  14.     This script posted to: 
  15.         http://www.pshscripts.blogspot.com 
  16.     This script posted to TechNet Scripting Gallery 
  17.         http://gallery.technet.microsoft.com/ScriptCenter/en-us/28e8b98e-565b-40be-ba2c-1134341bb555     
  18. .EXAMPLE 
  19.     PSH [C:\foo]: .Get-DnsRegisteredNames.ps1 
  20.     Computers reverse registered on DNS Server: Cookham1 
  21.     10.10.1.42      superman.cookham.net.                     3590550 
  22.     10.10.1.105     batman.cookham.net.                       3582112 
  23.     10.10.1.109     jeeves.cookham.net.                       3586452 
  24.     10.10.1.111     supergirl.cookham.net.                    3590550 
  25.     10.10.1.114     future.cookham.net.                       3589209 
  26.     10.10.1.131     bladerunner.cookham.net.                  3587817 
  27.     10.10.1.142     wonderwoman.kapoho.net.                   3590551 
  28. #> 
  29.  
  30. $dns = "Cookham1"  
  31. $records = get-wmiobject -class MicrosoftDNS_PTRType -namespace root\MicrosoftDNS -computer $dns  
  32.  
  33. "Computers reverse registered on DNS Server: $DNS" 
  34.  
  35. # Loop through and display results 
  36. foreach ($record in $records) { 
  37.  
  38. # Get owner name and ip address string 
  39. $on = $record.ownerName.split("."
  40. $ownerip = $on[3] + "." + $on[2] + "." + $on[1] + "." + $on[0] 
  41.  
  42. # Display details 
  43. "{0, -15} {1,-40}  {2,-10} " -f $ownerip, $record.ptrdomainname, $record.timestamp 

No comments: