Monday 30 April 2012

Show-DnsConfiguration.ps1

  1. <# 
  2. .SYNOPSIS 
  3.     This script shows the DNS Configuration  of NICs  
  4.     in your system 
  5. .DESCRIPTION 
  6.     This script is a re-write of an MSDN Sample  
  7.     using PowerShell./ The script gets all network 
  8.     active network interfaces then prints out that 
  9.     interfaces' DNS Properties. 
  10. .NOTES 
  11.     File Name  : Show-DnsConfiguration.ps1 
  12.     Author     : Thomas Lee - tfl@psp.co.uk 
  13.     Requires   : PowerShell Version 2.0 
  14. .LINK 
  15.     This script posted to: 
  16.         http://www.pshscripts.blogspot.com 
  17.     MSDN sample posted to: 
  18.          http://msdn.microsoft.com/en-us/library/system.net.networkinformation.networkinterface.getallnetworkinterfaces.aspx    
  19. .EXAMPLE 
  20.     Psh[C:\foo]> .\Show-DnsConfiguration.ps1 
  21.     Broadcom NetXtreme 57xx Gigabit Controller 
  22.       DNS suffix .............................. : cookham.net 
  23.       DNS enabled ............................. : False 
  24.       Dynamically configured DNS .............. : True 
  25.  
  26.     ... more interfaces snipped for brevity!     
  27. #> 
  28.  
  29. # Get the adapters than iterate over the collection and display DNS configuration 
  30. $adapters = [System.Net.NetworkInformation.NetworkInterface]::GetAllNetworkInterfaces() 
  31. ForEach ($adapter in $adapters)   { 
  32.   $properties = $adapter.GetIPProperties() 
  33.   $adapter.Description 
  34.   "  DNS suffix .............................. : {0}" -f $properties.DnsSuffix 
  35.   "  DNS enabled ............................. : {0}" -f $properties.IsDnsEnabled 
  36.   "  Dynamically configured DNS .............. : {0}" -f $properties.IsDynamicDnsEnabled 

Show-NetworkInterfaces2.ps1

  1. <# 
  2. .SYNOPSIS 
  3.     This script, shows details about the Network Interfaces 
  4.     on a system. This is a re-write of an MSDN script into 
  5.     PowerShell 
  6. .DESCRIPTION 
  7.     This script Uses several .NET classes to get the details 
  8.     of the interfaces on the system, then displays these details. 
  9.     Note in the MSDN Script, there were calls to other MSDN Samples.  
  10.     To make things simple, I have removed these calls.  
  11. .NOTES 
  12.     File Name  : Show-NetworkInterfaces2.ps1 
  13.     Author     : Thomas Lee - tfl@psp.co.uk 
  14.     Requires   : PowerShell Version 2.0 
  15. .LINK 
  16.     This script posted to: 
  17.         http://www.pshscripts.blogspot.com 
  18.     MSDN sample posted to: 
  19.          http://msdn.microsoft.com/en-us/library/system.net.networkinformation.networkinterface.aspx    
  20. .EXAMPLE 
  21.  
  22.     Psh[C:\foo]> .\Show-NetworkInterfaces2.ps1 
  23.     Interface information for Cookham8.cookham.net 
  24.       Number of interfaces .................... : 2 
  25.  
  26.     Broadcom NetXtreme 57xx Gigabit Controller 
  27.     ========================================== 
  28.       Interface type .......................... : Ethernet 
  29.       Physical Address ........................ : 001E4F955CC4 
  30.       Operational status ...................... : Up 
  31.       IP version .............................. : IPv4, IPv6 
  32.       DNS suffix .............................. : cookham.net 
  33.       MTU...................................... : 1500 
  34.       WINS Servers ............................ : 
  35.       10.10.1.101 
  36.       DNS enabled ............................. : False 
  37.       Dynamically configured DNS .............. : True 
  38.       Receive Only ............................ : False 
  39.       Multicast ............................... : True 
  40.  
  41.     Microsoft ISATAP Adapter 
  42.     ======================== 
  43.       Interface type .......................... : Tunnel 
  44.       Physical Address ........................ : 00000000000000E0 
  45.       Operational status ...................... : Down 
  46.       IP version .............................. : IPv4, IPv6 
  47.       DNS suffix .............................. : cookham.net 
  48.       MTU...................................... :  
  49.       DNS enabled ............................. : False 
  50.       Dynamically configured DNS .............. : True 
  51.       Receive Only ............................ : False 
  52.       Multicast ............................... : False 
  53.        
  54. #> 
  55.  
  56. # First, get network properties of, and the nics in, this system 
  57. $computerProperties = [System.Net.NetworkInformation.IPGlobalProperties]::GetIPGlobalProperties() 
  58. $nics =               [System.Net.NetworkInformation.NetworkInterface]::GetAllNetworkInterfaces() 
  59.  
  60. "Interface information for {0}.{1}" -f $computerProperties.HostName, $computerProperties.DomainName 
  61.  
  62. # Do we have nics?? 
  63. If (!$nics -or $nics.Length -lt 1) 
  64.     { 
  65.         "  No network interfaces found." 
  66.         return 
  67.     } 
  68.  
  69. # Show interface details 
  70. "  Number of interfaces .................... : {0}" -f $nics.Length 
  71. ForEach ($adapter in $nics
  72.     { 
  73.         $properties = $adapter.GetIPProperties() 
  74.         "" 
  75.         $adapter.Description 
  76.         "=" * $adapter.Description.Length 
  77.         "  Interface type .......................... : {0}" -f $adapter.NetworkInterfaceType 
  78.         "  Physical Address ........................ : {0}" -f $adapter.GetPhysicalAddress().ToString() 
  79.         "  Operational status ...................... : {0}" -f $adapter.OperationalStatus 
  80.     # Create a display string for the supported IP versions. 
  81.        $versions ="" 
  82.         if ($adapter.Supports([System.Net.NetworkInformation.NetworkInterfaceComponent]::IPV4 )) 
  83.         { 
  84.              $versions = "IPv4" 
  85.          } 
  86.         if ($adapter.Supports([System.Net.NetworkInformation.NetworkInterfaceComponent]::IPv6)) 
  87.         { 
  88.             if ($versions.Length -gt 0) 
  89.             { 
  90.                $versions += ", "
  91.              } 
  92.             $versions += "IPv6"
  93.         } 
  94.         "  IP version .............................. : {0}" -f $versions 
  95.  
  96. # The remaining information is not useful for loopback adapters. 
  97.  if ($adapter.NetworkInterfaceType -eq [System.Net.NetworkInformation.NetworkInterfaceType]::Loopback) 
  98.         { 
  99.             continue 
  100.         } 
  101.  "  DNS suffix .............................. : {0}" -f $properties.DnsSuffix 
  102.         if ($adapter.Supports([System.Net.NetworkInformation.NetworkInterfaceComponent]::IPv4)) 
  103.         { 
  104.             $ipv4 = $properties.GetIPv4Properties() 
  105.             "  MTU...................................... : {0}" -f $ipv4.Mtu 
  106.             if ($ipv4.UsesWins) 
  107.             { 
  108.  
  109.                 $winsServers = $properties.WinsServersAddresses 
  110.                 if ($winsServers.Count -gt 0) 
  111.                 { 
  112.                     "  WINS Servers ............................ :"
  113.                     foreach ($Winserver in $winsServers) { 
  114.                     "  {0}" -f $Winserver.IpAddressToString 
  115.                     } 
  116.                 } 
  117.             } 
  118.         } 
  119.  
  120.         "  DNS enabled ............................. : {0}" -f $properties.IsDnsEnabled 
  121.         "  Dynamically configured DNS .............. : {0}" -f $properties.IsDynamicDnsEnabled 
  122.         "  Receive Only ............................ : {0}" -f $adapter.IsReceiveOnly 
  123.         "  Multicast ............................... : {0}" -f $adapter.SupportsMulticast 
  124. # End Foreach 

Sunday 29 April 2012

Show-NetworkInterfaces1.ps1

  1. <# 
  2. .SYNOPSIS 
  3.     This script displays the NICs in a system and their physical
  4.     address. 
  5. .DESCRIPTION 
  6.     This script is a MSDN Sample recoded in PowerShell. The script
  7.     first gets all the interfaces on the system, then loops through
  8.     them displaying more information about them to the console.
  9.     Note the use of Console.Write in the loop at the end. Not quite
  10.     sure a better PowerShell equivalent other than creating a
  11.     string with all the bytes, then displaying that string. 
  12. .NOTES 
  13.     File Name  : Show-NetworkInterfaces1.ps1 
  14.     Author     : Thomas Lee - tfl@psp.co.uk 
  15.     Requires   : PowerShell Version 2.0 
  16. .LINK 
  17.     This script posted to: 
  18.         http://www.pshscripts.blogspot.com 
  19.     MSDN sample posted to: 
  20.         http://msdn.microsoft.com/en-us/library/system.net.networkinformation.physicaladdress.aspx    
  21. .EXAMPLE 
  22.     PSH[c:\foo]> .\Show-Networkinterfaces1.ps1 
  23. Interface information for Cookham8.cookham.net      
  24.   Number of interfaces .................... : 2 
  25. Broadcom NetXtreme 57xx Gigabit Controller 
  26. ========================================== 
  27.   Interface type .......................... : Ethernet 
  28.   Physical address ........................ : 00-1E-4F-95-5C-C4  
  29.  
  30. Microsoft ISATAP Adapter 
  31. ======================== 
  32.   Interface type .......................... : Tunnel 
  33.   Physical address ........................ : 00-00-00-00-00-00-00-E0  
  34.      
  35. #> 
  36.      
  37. # Get computer IP global properties 
  38. $ComputerProperties = [System.Net.NetworkInformation.IpGlobalProperties]::GetIPGlobalProperties() 
  39.  
  40. # Get the nics in this system 
  41. $nics = [System.Net.NetworkInformation.NetworkInterface]::GetAllNetworkInterfaces() 
  42.  
  43. # Show information header 
  44. "Interface information for {0}.{1}     " -f $ComputerProperties.HostName, $ComputerProperties.DomainName 
  45.   
  46. # Iterate through the NIcs ans outout per nic info 
  47. # First, check if interfaces are found 
  48.  if (!$nics -OR $nics.Length -LT 1) 
  49.     { 
  50.         "  No network interfaces found." 
  51.         return 
  52.     } 
  53.  
  54. # Here print out number of interfaces and interface details 
  55. [System.Console]::WriteLine("  Number of interfaces .................... : {0}" -f $nics.Length) 
  56. Foreach ($adapter in $nics
  57.     { 
  58.         $properties = $adapter.GetIPProperties();    
  59.         " ";"" 
  60.         "{0}" -F $adapter.Description 
  61.         "=" * $adapter.Description.Length 
  62.         "  Interface type .......................... : {0}" -F $adapter.NetworkInterfaceType 
  63.         [System.Console]::Write("  Physical address ........................ : "
  64.         $address = $adapter.GetPhysicalAddress(); 
  65.         $bytes = $address.GetAddressBytes() 
  66.         for($i = 0; $i -lt $bytes.Length; $i++) 
  67.         { 
  68.             # Display the physical address in hexadecimal. 
  69.             [system.Console]::Write("{0}" -f $bytes[$i].ToString("X2")) 
  70.             # Insert a hyphen after each byte, unless we are at the end of the  
  71.             # address. 
  72.             if ($i -NE $bytes.Length -1) 
  73.             { 
  74.                  [System.Console]::Write("-"
  75.             } 
  76.         } 
  77.         [System.Console]::WriteLine() 
  78.     }