- <#
- .SYNOPSIS
- This script shows the DNS Configuration of NICs
- in your system
- .DESCRIPTION
- This script is a re-write of an MSDN Sample
- using PowerShell./ The script gets all network
- active network interfaces then prints out that
- interfaces' DNS Properties.
- .NOTES
- File Name : Show-DnsConfiguration.ps1
- Author : Thomas Lee - tfl@psp.co.uk
- Requires : PowerShell Version 2.0
- .LINK
- This script posted to:
- http://www.pshscripts.blogspot.com
- MSDN sample posted to:
- http://msdn.microsoft.com/en-us/library/system.net.networkinformation.networkinterface.getallnetworkinterfaces.aspx
- .EXAMPLE
- Psh[C:\foo]> .\Show-DnsConfiguration.ps1
- Broadcom NetXtreme 57xx Gigabit Controller
- DNS suffix .............................. : cookham.net
- DNS enabled ............................. : False
- Dynamically configured DNS .............. : True
- ... more interfaces snipped for brevity!
- #>
- # Get the adapters than iterate over the collection and display DNS configuration
- $adapters = [System.Net.NetworkInformation.NetworkInterface]::GetAllNetworkInterfaces()
- ForEach ($adapter in $adapters) {
- $properties = $adapter.GetIPProperties()
- $adapter.Description
- " DNS suffix .............................. : {0}" -f $properties.DnsSuffix
- " DNS enabled ............................. : {0}" -f $properties.IsDnsEnabled
- " Dynamically configured DNS .............. : {0}" -f $properties.IsDynamicDnsEnabled
- }
This blog contains PowerShell scripts, more PowerShell scripts and still more PowerShell scripts. Occasionally you may see some organisational posts.
Monday, 30 April 2012
Show-DnsConfiguration.ps1
Show-NetworkInterfaces2.ps1
- <#
- .SYNOPSIS
- This script, shows details about the Network Interfaces
- on a system. This is a re-write of an MSDN script into
- PowerShell
- .DESCRIPTION
- This script Uses several .NET classes to get the details
- of the interfaces on the system, then displays these details.
- Note in the MSDN Script, there were calls to other MSDN Samples.
- To make things simple, I have removed these calls.
- .NOTES
- File Name : Show-NetworkInterfaces2.ps1
- Author : Thomas Lee - tfl@psp.co.uk
- Requires : PowerShell Version 2.0
- .LINK
- This script posted to:
- http://www.pshscripts.blogspot.com
- MSDN sample posted to:
- http://msdn.microsoft.com/en-us/library/system.net.networkinformation.networkinterface.aspx
- .EXAMPLE
- Psh[C:\foo]> .\Show-NetworkInterfaces2.ps1
- Interface information for Cookham8.cookham.net
- Number of interfaces .................... : 2
- Broadcom NetXtreme 57xx Gigabit Controller
- ==========================================
- Interface type .......................... : Ethernet
- Physical Address ........................ : 001E4F955CC4
- Operational status ...................... : Up
- IP version .............................. : IPv4, IPv6
- DNS suffix .............................. : cookham.net
- MTU...................................... : 1500
- WINS Servers ............................ :
- 10.10.1.101
- DNS enabled ............................. : False
- Dynamically configured DNS .............. : True
- Receive Only ............................ : False
- Multicast ............................... : True
- Microsoft ISATAP Adapter
- ========================
- Interface type .......................... : Tunnel
- Physical Address ........................ : 00000000000000E0
- Operational status ...................... : Down
- IP version .............................. : IPv4, IPv6
- DNS suffix .............................. : cookham.net
- MTU...................................... :
- DNS enabled ............................. : False
- Dynamically configured DNS .............. : True
- Receive Only ............................ : False
- Multicast ............................... : False
- #>
- # First, get network properties of, and the nics in, this system
- $computerProperties = [System.Net.NetworkInformation.IPGlobalProperties]::GetIPGlobalProperties()
- $nics = [System.Net.NetworkInformation.NetworkInterface]::GetAllNetworkInterfaces()
- "Interface information for {0}.{1}" -f $computerProperties.HostName, $computerProperties.DomainName
- # Do we have nics??
- If (!$nics -or $nics.Length -lt 1)
- {
- " No network interfaces found."
- return
- }
- # Show interface details
- " Number of interfaces .................... : {0}" -f $nics.Length
- ForEach ($adapter in $nics)
- {
- $properties = $adapter.GetIPProperties()
- ""
- $adapter.Description
- "=" * $adapter.Description.Length
- " Interface type .......................... : {0}" -f $adapter.NetworkInterfaceType
- " Physical Address ........................ : {0}" -f $adapter.GetPhysicalAddress().ToString()
- " Operational status ...................... : {0}" -f $adapter.OperationalStatus
- # Create a display string for the supported IP versions.
- $versions =""
- if ($adapter.Supports([System.Net.NetworkInformation.NetworkInterfaceComponent]::IPV4 ))
- {
- $versions = "IPv4"
- }
- if ($adapter.Supports([System.Net.NetworkInformation.NetworkInterfaceComponent]::IPv6))
- {
- if ($versions.Length -gt 0)
- {
- $versions += ", ";
- }
- $versions += "IPv6";
- }
- " IP version .............................. : {0}" -f $versions
- # The remaining information is not useful for loopback adapters.
- if ($adapter.NetworkInterfaceType -eq [System.Net.NetworkInformation.NetworkInterfaceType]::Loopback)
- {
- continue
- }
- " DNS suffix .............................. : {0}" -f $properties.DnsSuffix
- if ($adapter.Supports([System.Net.NetworkInformation.NetworkInterfaceComponent]::IPv4))
- {
- $ipv4 = $properties.GetIPv4Properties()
- " MTU...................................... : {0}" -f $ipv4.Mtu
- if ($ipv4.UsesWins)
- {
- $winsServers = $properties.WinsServersAddresses
- if ($winsServers.Count -gt 0)
- {
- " WINS Servers ............................ :";
- foreach ($Winserver in $winsServers) {
- " {0}" -f $Winserver.IpAddressToString
- }
- }
- }
- }
- " DNS enabled ............................. : {0}" -f $properties.IsDnsEnabled
- " Dynamically configured DNS .............. : {0}" -f $properties.IsDynamicDnsEnabled
- " Receive Only ............................ : {0}" -f $adapter.IsReceiveOnly
- " Multicast ............................... : {0}" -f $adapter.SupportsMulticast
- } # End Foreach
Sunday, 29 April 2012
Show-NetworkInterfaces1.ps1
- <#
- .SYNOPSIS
- This script displays the NICs in a system and their physical
- address.
- .DESCRIPTION
- This script is a MSDN Sample recoded in PowerShell. The script
- first gets all the interfaces on the system, then loops through
- them displaying more information about them to the console.
- Note the use of Console.Write in the loop at the end. Not quite
- sure a better PowerShell equivalent other than creating a
- string with all the bytes, then displaying that string.
- .NOTES
- File Name : Show-NetworkInterfaces1.ps1
- Author : Thomas Lee - tfl@psp.co.uk
- Requires : PowerShell Version 2.0
- .LINK
- This script posted to:
- http://www.pshscripts.blogspot.com
- MSDN sample posted to:
- http://msdn.microsoft.com/en-us/library/system.net.networkinformation.physicaladdress.aspx
- .EXAMPLE
- PSH[c:\foo]> .\Show-Networkinterfaces1.ps1
- Interface information for Cookham8.cookham.net
- Number of interfaces .................... : 2
- Broadcom NetXtreme 57xx Gigabit Controller
- ==========================================
- Interface type .......................... : Ethernet
- Physical address ........................ : 00-1E-4F-95-5C-C4
- Microsoft ISATAP Adapter
- ========================
- Interface type .......................... : Tunnel
- Physical address ........................ : 00-00-00-00-00-00-00-E0
- #>
- # Get computer IP global properties
- $ComputerProperties = [System.Net.NetworkInformation.IpGlobalProperties]::GetIPGlobalProperties()
- # Get the nics in this system
- $nics = [System.Net.NetworkInformation.NetworkInterface]::GetAllNetworkInterfaces()
- # Show information header
- "Interface information for {0}.{1} " -f $ComputerProperties.HostName, $ComputerProperties.DomainName
- # Iterate through the NIcs ans outout per nic info
- # First, check if interfaces are found
- if (!$nics -OR $nics.Length -LT 1)
- {
- " No network interfaces found."
- return
- }
- # Here print out number of interfaces and interface details
- [System.Console]::WriteLine(" Number of interfaces .................... : {0}" -f $nics.Length)
- Foreach ($adapter in $nics)
- {
- $properties = $adapter.GetIPProperties();
- " ";""
- "{0}" -F $adapter.Description
- "=" * $adapter.Description.Length
- " Interface type .......................... : {0}" -F $adapter.NetworkInterfaceType
- [System.Console]::Write(" Physical address ........................ : ")
- $address = $adapter.GetPhysicalAddress();
- $bytes = $address.GetAddressBytes()
- for($i = 0; $i -lt $bytes.Length; $i++)
- {
- # Display the physical address in hexadecimal.
- [system.Console]::Write("{0}" -f $bytes[$i].ToString("X2"))
- # Insert a hyphen after each byte, unless we are at the end of the
- # address.
- if ($i -NE $bytes.Length -1)
- {
- [System.Console]::Write("-")
- }
- }
- [System.Console]::WriteLine()
- }
Subscribe to:
Posts (Atom)