Monday, 30 April 2012

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 

No comments: