Tuesday 4 August 2009

Get-DNSAddress.ps1

  1. <# 
  2. .SYNOPSIS 
  3.     This script uses the System.Net.Networkinginformation.Networknterface class 
  4.     to get all network interface detais and displays the DNS addresses configured. 
  5. .DESCRIPTION 
  6.     This script first gets all the interface objects, then iterates throught them to  
  7.     get the DNS address(es) configured for each one. 
  8. .NOTES 
  9.     File Name  : Get-DNSAddress.ps1 
  10.     Author     : Thomas Lee - tfl@psp.co.uk 
  11.     Requires   : PowerShell V2 CTP3 
  12. .LINK 
  13.     This script posted to: 
  14.     http://www.pshscripts.blogspot.com 
  15.     MSDN Sample posted at: 
  16.     http://msdn.microsoft.com/en-us/library/system.net.networkinformation.ipaddressinformation(VS.85).aspx 
  17. .EXAMPLE 
  18.     PSH [C:\foo]: . 'C:\Users\tfl\AppData\Local\Temp\Untitled11.ps1' 
  19.     NETGEAR FA311v2 PCI Adapter - Virtual Network 
  20.       DNS Servers ............................. : 10.10.1.101 
  21.     Broadcom NetXtreme Gigabit Ethernet 
  22.       DNS Servers ............................. : 10.10.1.101 
  23.     Software Loopback Interface 1 
  24.       DNS Servers ............................. : fec0:0:0:ffff::1%1 
  25.       DNS Servers ............................. : fec0:0:0:ffff::2%1 
  26.       DNS Servers ............................. : fec0:0:0:ffff::3%1 
  27.     isatap.cookham.net 
  28.       DNS Servers ............................. : 10.10.1.101 
  29. #> 
  30.   
  31. ## 
  32. # Start of Script 
  33. ## 
  34.  
  35. # Get set of adapters 
  36. $adapters  = [System.Net.NetworkInformation.NetworkInterface]::GetAllNetworkInterfaces() 
  37.   
  38. # For each adapter, print out DNS Server Addresses configured 
  39. foreach ($adapter in $adapters) { 
  40.   $AdapterProperties = $Adapter.GetIPProperties() 
  41.   $dnsServers        = $AdapterProperties.DnsAddresses 
  42.   if ($dnsServers.Count -gt 0){ 
  43.     $adapter.Description 
  44.     foreach ($IPAddress in $dnsServers) { 
  45.         "  DNS Servers ............................. : {0}" -f $ipaddress.IPAddressToString 
  46.             } 
  47.     } 
  48. }    
  49. # End of Script 

No comments: