Monday, June 25, 2018

The Command:

Get-Module -ListAvailable

brings a large number of modules to the screen, many of which are labeled "Net", and therefore are of particular interest to the administrator when they need information about their network and corresponding hardware, such as the network adapter. Another command of this type:

Get-Command -Module NetTCPIP

then shows again which commands are available within the NetTCPIP module. System administrators who need information about their network will usually use the "ipconfig" command - which can also be started directly from the PowerShell command line. Similar to "netsh", however, the user often has to torment himself by going through various submenus before he gets the desired information. 
Selecting the corresponding PowerShell Cmdlet makes it much easier. If you need information on the IP address, you can get it with the following command:

Get-NetIPAddress

It will then display both the configuration information for the IPv4 and the IPv6 addresses for all network adapters in the system. On a server system with multiple network cards, many entries are displayed. Those who are then overwhelmed by the wealth of information displayed can filter the output accordingly. If only the basic information is needed, usually the Format-Table Cmdlet (to which the output is passed by means of a pipeline) helps:

Get-NetIPAddress | Format-Table

Of course, it is also possible to reduce the output to just the addresses in the IPv4 range:

Get-NetIPAddress -Addressfamily IPv4 | Format-Table

A very useful Cmdlet also displays all the network interfaces installed on the computer directly:

Get-NetAdapter

Again, it is easily possible to filter the output further. For example, when it comes to listing only the existing WLAN interfaces:

Get-NetAdapter -Name "WLAN"

The commands and thus also the gained information are truly flexible due to the fact that the PowerShell commands can be linked by means of a pipeline (as already briefly shown with Format-Table). What about, for example, displaying only the IP addresses in the system that were assigned via DHCP? To do so, we first use the Get-NetIPAddress Cmdlet, which displays the existing IP addresses. This output is passed to "Where-Object". There, the addresses that were assigned by DHCP are then filtered out by comparing the prefix (-eq stands for "equal"). Once again forwarded to "Select-Object", then only the name and the IP address of the found interfaces are displayed:
Get-NetIPAddress |
  Where-Object PrefixOrigin -eq dhcp |
  Select-Object -Property IPAddress, InterFaceAlias
Even these few examples clearly show the potential in PowerShell network commands, which can also be used remotely on other Windows systems. System managers and administrators should familiarize themselves with these possibilities, and in this way, create their own library with scripts for network support. A good starting point for everything about PowerShell can be found on the Internet in the blog "Hey Scripting Guy!"(part of Microsoft TechNet). But there are simple scripts for beginners, as well as complex, more comprehensive solutions and examples.

No comments:

Post a Comment