The purpose of this page is control the output of Ipconfig with PowerShell’s Select-String.
PowerShell v3 Ipconfig
- Introduction to PowerShell and Ipconfig
- Example 1: To List Just IP Addresses
- Example 2: To Display the Default Gateway
- Troubleshooting Ipconfig
Ipconfig has been built-in to each Microsoft operating systems from Windows 3.11 onwards. My primary use of this utility is to display a computer’s IP or MAC address. Other common use of Ipconfig is to release and renew IP address leases for DHCP clients.
Traditionally, Ipconfig has been used in a DOS box. One of my ways of weaning people away from CMD.exe and into PowerShell ISE, is to persuade them to run native utilities, such as Ipconfig, in PowerShell instead of cmd.
The purpose of this page is to give extra reasons for using PowerShell by adding useful supplementary commands such as Select-String, or its new alias ‘sls’.
Let us take stock: we are using the built-in operating system command Ipconfig and then piping (|) the output into Select-String, where we filter the data for ‘IP’ information.
Ipconfig | Select-String IP
Windows IP Configuration
Link-local IPv6 Address: fe80::c45b:a402:b918:8454%10
IPv4 Address: 192.168.1.47
IPv6 Address: 2001:0:5ef5:79fb:1c91:379:3f57:fed3
Link-local IPv6 Address: fe80::1c91:379:3f57:fed3%13
Note 1: For comparison you could try plain:
The above example almost begs you to select other information, for instance, instead of ‘IP’ you could try ‘IPv4’, ‘Gateway’, or even DNS. Also observe below how I substitute the alias ‘sls’ for Select-String.
Ipconfig | sls Gate
Default Gateway . . . . . . . . . : 192.168.1.254
SolarWinds’ Network Performance Monitor will help you discover what’s happening on your network. This utility will also guide you through troubleshooting; the dashboard will indicate whether the root cause is a broken link, faulty equipment or resource overload.
What I like best is the way NPM suggests solutions to network problems. Its also has the ability to monitor the health of individual VMware virtual machines. If you are interested in troubleshooting, and creating network maps, then I recommend that you try NPM now.
Research More Ipconfig Switches
Get-Help does not work with Ipconfig, however you can use its native help command /? thus:
Amongst the parameters listed /release and /renew the most commonly used, and useful commands that are often forgotten are: Ipconfig /flushdns and /displaydns.
Here are ideas for using PowerShell to overcome common problems with Ipconfig.
Problem: Why can’t you see the MAC address?
Solution: PowerShell with Ipconfig’s /All parameter.
# PowerShell MAC Address script
Ipconfig | sls Physical
# Compare with /all
Ipconfig /all | sls Physical
Physical Address. . . . . . . . . : 20-CF-30-3A-B5-72
Physical Address is the formal name for MAC address.
Problem: ‘Ipconfig’ is not recognized as an internal or external command, operable program or batch file.
Solution: Check the path to Ipconfig:
Result: You should see: C:\Windows\system32; if not then append this folder to the path thus:
$env:Path = $env:Path +";$env:windir\system32;
Check that the executable exists: just in case someone has deleted ipconfig try this:
Test-Path -path "$env:windir\system32\ipconfig.exe"
Build a Function Get-IPConfig
Another strategy is to build your own PowerShell function based on ideas from this page. For example we could build a function called -MAC which would display the Physical Address, for example: 20-CF-30-3A-B3-73.
Summary of PowerShell Ipconfig with Select-String
Ipconfig was once used exclusively in a DOS box. One of my ways of weaning people away from CMD.exe and into PowerShell ISE, is to persuade them to run native utilities, such as Ipconfig, in PowerShell instead of cmd. The killer reason for switching is combining Ipconfig with Select-String.
If you like this page then please share it with your friends
See more Microsoft PowerShell tutorials
If you see an error of any kind, do let me know. Please report any factual mistakes, grammatical errors or broken links.