- <#
- .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.
Showing posts with label System.Net.NetworkInformation. Show all posts
Showing posts with label System.Net.NetworkInformation. Show all 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()
- }
Wednesday, 21 October 2009
Get-DNSInfo.ps1
- <#
- .SYNOPSIS
- This script re-implements a MSDN Sample in PowerShell that
- shows the use of System.Net.NetworkInformation.NetworkInterface
- .DESCRIPTION
- This script gets network information and formats DNS info. The
- script is effectively a one-liner!
- .NOTES
- File Name : Get-DNSInfo.ps1
- Author : Thomas Lee - tfl@psp.co.uk
- Requires : PowerShell V2
- .LINK
- This script posted to:
- http://www.pshscripts.blogspot.com
- MSDN Sample posted at:
- http://msdn.microsoft.com/en-us/library/system.net.networkinformation.networkinterface.getallnetworkinterfaces.aspx
- .EXAMPLE
- PSH [C:\foo]: . 'E:\PowerShellScriptLib\System.Net.NetworkInformation\Get-DNSInfo.ps1'
- DnsSuffix IsDnsEnabled IsDynamicDnsEnabled
- --------- ------------ -------------------
- cookham.net False True
- cookham.net False True
- False True
- cookham.net False True
- #>
- ##
- # Start of script
- ##
- #Get information and print - do this as a 1-liner!
- [System.Net.Networkinformation.NetworkInterface]::GetAllNetworkInterfaces() | %{$_.GetIpProperties()} | FT Dnssuffix,Isdnsenabled,IsDynamicDnsEnabled -a
- # End of script
Tuesday, 4 August 2009
Get-DNSAddress.ps1
- <#
- .SYNOPSIS
- This script uses the System.Net.Networkinginformation.Networknterface class
- to get all network interface detais and displays the DNS addresses configured.
- .DESCRIPTION
- This script first gets all the interface objects, then iterates throught them to
- get the DNS address(es) configured for each one.
- .NOTES
- File Name : Get-DNSAddress.ps1
- Author : Thomas Lee - tfl@psp.co.uk
- Requires : PowerShell V2 CTP3
- .LINK
- This script posted to:
- http://www.pshscripts.blogspot.com
- MSDN Sample posted at:
- http://msdn.microsoft.com/en-us/library/system.net.networkinformation.ipaddressinformation(VS.85).aspx
- .EXAMPLE
- PSH [C:\foo]: . 'C:\Users\tfl\AppData\Local\Temp\Untitled11.ps1'
- NETGEAR FA311v2 PCI Adapter - Virtual Network
- DNS Servers ............................. : 10.10.1.101
- Broadcom NetXtreme Gigabit Ethernet
- DNS Servers ............................. : 10.10.1.101
- Software Loopback Interface 1
- DNS Servers ............................. : fec0:0:0:ffff::1%1
- DNS Servers ............................. : fec0:0:0:ffff::2%1
- DNS Servers ............................. : fec0:0:0:ffff::3%1
- isatap.cookham.net
- DNS Servers ............................. : 10.10.1.101
- #>
- ##
- # Start of Script
- ##
- # Get set of adapters
- $adapters = [System.Net.NetworkInformation.NetworkInterface]::GetAllNetworkInterfaces()
- # For each adapter, print out DNS Server Addresses configured
- foreach ($adapter in $adapters) {
- $AdapterProperties = $Adapter.GetIPProperties()
- $dnsServers = $AdapterProperties.DnsAddresses
- if ($dnsServers.Count -gt 0){
- $adapter.Description
- foreach ($IPAddress in $dnsServers) {
- " DNS Servers ............................. : {0}" -f $ipaddress.IPAddressToString
- }
- }
- }
- # End of Script
Subscribe to:
Posts (Atom)