What is the PowerShell equivalent of ipconfig?

Brock Bingham candid headshot
Brock Bingham|February 25, 2021
What Is The PowerShell Equivalent Of IPConfig
What Is The PowerShell Equivalent Of IPConfig

IPconfig is probably my most used CMD utility. It’s great. Need the IP address? Just crack open a command prompt window, slap in ipconfig, hit enter, and you’re done. If you need more information like the subnet mask and default gateway, simply use ipconfig /all, and you’ve got all the information you need within seconds. Even my non-tech-savvy users learned how to use it because when they would need support, I would call them and walk them through how to get their IP address using the ipconfig command.

Of course, there are other methods you could use to get the IP address of a computer. You could check the address leases on your DHCP server, or you could check the entries on your DNS server. You could check the network configuration settings in the control panel. You could even use PDQ Inventory. Even with all those different ways of getting an IP address, ipconfig was still my go-to. It’s an old friend that’s never let me down. However, with PowerShell taking over as the new kid on the block, do I have to say goodbye to my old friend? Let’s find out.

CMD vs. PowerShell

Don’t be confused. Just because CMD and PowerShell can run many of the same commands doesn’t mean these two shells are the same. There really is no comparison here. PowerShell is drastically more powerful than CMD. It can do everything CMD can do and so much more. PowerShell is a scripting language built on the .net framework and has access to all of the .net libraries. Nearly everything in PowerShell is an object with properties and methods which can be called and manipulated. Administrators can use PowerShell to manage almost every part of the Windows environment and automate complex administrative tasks. Command prompt, by comparison, is not an object-oriented language and is very limited, having a much smaller set of commands and functions that it can perform.

Using IPConfig in PowerShell

I always like to get this out of the way first; many of the CMD commands you know and love still work in PowerShell. Go ahead, try it.

ipconfig

Again, since PowerShell can use almost all of the old CMD commands, you should really stop procrastinating and make the switch.

Using the old command is fine, and at least it will get you comfortable launching PowerShell by default instead of CMD. However, to make the most out of PowerShell, you need to use the proper PowerShell commands. For IPConfig, we have a couple of PowerShell options to use, so let’s break down each.

The PowerShell equivalent of IPConfig is Get-NetIPConfiguration & Get-NetIPAddress

Let’s first take a look at the PowerShell option that the most closely resembles the functionality and results of IPConfig, Get-NetIPConfiguration.

NAME Get-NetIPAddress SYNOPSIS Gets the IP address configuration. SYNTAX Get-NetIPAddress [[-IPAddress] <String[]>] [-AddressFamily <AddressFamily[]>] [-AddressState <AddressState[]>] [-AssociatedIPInterface <CimInstance>] [-CimSession <CimSession[]>] [-IncludeAllCompartments] [-InterfaceAlias<String[]>] [-InterfaceIndex <UInt32[]>] [-PolicyStore <String>] [-PreferredLifetime <TimeSpan[]>] [-PrefixLength <Byte[]>] [-PrefixOrigin <PrefixOrigin[]>] [-SkipAsSource <Boolean[]>] [-SuffixOrigin <SuffixOrigin[]>] [-ThrottleLimit <Int32>] [-Type <Type[]>] [-ValidLifetime <TimeSpan[]>] [<CommonParameters>] DESCRIPTION The Get-NetIPAddress cmdlet gets the IP address configuration, such as IPv4 addresses, IPv6 addresses and the IP interfaces with which addresses are associated. Without parameters, this cmdlet gets the entire IP address configuration for the computer. RELATED LINKS Online Version: http://go.microsoft.com/fwlink/?LinkId=288380 Get-NetRoute New-NetIPAddress Remove-NetIPAddress Set-NetIPAddress REMARKS To see the examples, type: "get-help Get-NetIPAddress -examples". For more information, type: "get-help Get-NetIPAddress -detailed". For technical information, type: "get-help Get-NetIPAddress -full". For online help, type: "get-help Get-NetIPAddress -online"

Here’s a comparison between the data returned with IPConfig versus the data returned with Get-NetIPConfiguration.

ipconfig2

As the description says, Get-NetIPConfiguration returns networking configuration, including usable interfaces, IP addresses, and DNS servers. This command by itself will return all of the non-virtual connected interfaces on the computer. If you want to return the virtual interfaces, you will need to include the -All parameter.

Now let’s look at the cmdlet Get-NetIPAddress, which returns IPv4 and IPv6 configuration data and information about the interfaces those addresses are associated with.

NAME Get-NetIPAddress SYNOPSIS Gets the IP address configuration. SYNTAX Get-NetIPAddress [[-IPAddress] <String[]>] [-AddressFamily <AddressFamily[]>] [-AddressState <AddressState[]>] [-AssociatedIPInterface <CimInstance>] [-CimSession <CimSession[]>] [-IncludeAllCompartments] [-InterfaceAlias<String[]>] [-InterfaceIndex <UInt32[]>] [-PolicyStore <String>] [-PreferredLifetime <TimeSpan[]>] [-PrefixLength <Byte[]>] [-PrefixOrigin <PrefixOrigin[]>] [-SkipAsSource <Boolean[]>] [-SuffixOrigin <SuffixOrigin[]>] [-ThrottleLimit <Int32>] [-Type <Type[]>] [-ValidLifetime <TimeSpan[]>] [<CommonParameters>] DESCRIPTION The Get-NetIPAddress cmdlet gets the IP address configuration, such as IPv4 addresses, IPv6 addresses and the IP interfaces with which addresses are associated. Without parameters, this cmdlet gets the entire IP address configuration for the computer. RELATED LINKS Online Version: http://go.microsoft.com/fwlink/?LinkId=288380 Get-NetRoute New-NetIPAddress Remove-NetIPAddress Set-NetIPAddress REMARKS To see the examples, type: "get-help Get-NetIPAddress -examples". For more information, type: "get-help Get-NetIPAddress -detailed". For technical information, type: "get-help Get-NetIPAddress -full". For online help, type: "get-help Get-NetIPAddress -online"

Here is a comparison of the returned data.

ipconfig3

Notice that the PowerShell cmdlet returned much more information about this device’s associated IP addresses, even including the loopback or localhost address. I cropped this image because of the amount of data returned, but I’ll show you how to return this information in a much more digestible format.

Get-NetIPConfiguration and Get-NetIPAddress examples

Armed with this new PowerShell knowledge, let’s look at some practical examples and use cases.

Get-NetIPConfiguration example 1

Get-NetIPConfiguration | Select-Object -Property IPv4Address
ipconfig5

This example returns just the IPv4 address of the local computer. Since I’m usually looking for the IPv4 address when I run this command, this will ignore the other properties and only return the IPv4 address property. To understand how this command works, let’s first talk about the “|” symbol. This symbol is the vertical bar or pipe symbol. This symbol allows you to pipe or pass results from one cmdlet to another. In this case, we are passing on the results of Get-NetIPConfiguration to the Select-Object cmdlet. The Select-Object cmdlet allows you to select specific properties of an object. I’ve used the -Property parameter to target only the IPv4Address property.

Get-NetIPConfiguration example 2

Get-NetIPConfiguration -Computer “computer-name” | Select-Object -Property IPv4Address

This example returns the IPv4Address of a remote computer. We are using the -Computer parameter to specify a remote host. For this example to work, you need to ensure that PowerShell remoting is enabled. You can check to see if this is enabled on the remote machine by running the command Get-Service “Winrm. If it’s not configured, you can run Winrm quickconfig, which should enable the service for you. If you need to allow PowerShell remoting on several machines or you want to enable it on your entire domain, your best bet is to configure it through Group Policy.

Get-NetIPAddress example 1

Get-NetIPAddress | Format-Table
ipconfig4

Like I mentioned previously, Get-NetIPAddress can end up returning a lot of information and not in a format that’s easy to read. To solve this, we can pipe the results of the Get-NetIPAddress cmdlet to the Format-Table cmdlet, which will, as the name suggests, display the resultant data in an easy-to-digest table format. Just a heads up, once you format this data into a table, you can no longer interact with it.

Get-NetIPAddress example 2

$list = "computer1", "computer2", "computer3" $Array = New-Object System.Collections.ArrayList Foreach ($Machine in $list){ $result = Get-NetIPAddress -CimSession $Machine -PrefixOrigin Dhcp $Array.Add($result) | Out-Null } $Array | Select PSComputerName, IPAddress
ipconfig6

This example takes things to the next level so let’s unpack it and see what’s going on.

First, we are assigning three computers to the $list variable. Next, we create a variable called $Array and configure it as an array object with New-Object System.Collections.ArrayList. Then, we start our Foreach loop, which will use a placeholder variable called $Machine to contain an individual item from the $list variable while running through the loop. Next, we create a variable named $result, which will contain the results from the Get-NetIPAddress cmdlet. We’ve added the -CimSession parameter that will connect to the remote computer currently assigned to the placeholder variable $Machine. We’ve used the parameter -PrefixOrigin to single out only IP addresses with the prefix origin of Dhcp. Next, we add the $result variable to the $Array with $Array.Add($result) and pipe that to Out-Null to stop the array from printing output while assigning results. Lastly, we call the array to show the resultant data but only display the PSComputerName and IPAddress to keep our results nice and clean.

This script is pretty versatile and could easily be modified to return the IP addresses of all the computers in a specified OU versus just manually inputting computer names. As a word of caution, if you run this script against a computer that is not online, an error will be thrown, but the script will continue to run. The end result will be a duplicate entry in the array.

Wrapping up

If you haven’t already, now’s the time to start learning PowerShell. As its name implies, it’s a very powerful tool that can help you manage and even automate many of your sysadmin responsibilities.

If you’re interested in other tools that can help manage or automate your tasks, you should check out PDQ Deploy and PDQ Inventory and PDQ Connect. Priced to fit any budget, this powerful combination can collect hardware, software, and Windows configuration data and automate your package deployments to keep your machines always up to date. You can try them out for yourself with a free 14-day trial.

Brock Bingham candid headshot
Brock Bingham

Born in the '80s and raised by his NES, Brock quickly fell in love with everything tech. With over 15 years of IT experience, Brock now enjoys the life of luxury as a renowned tech blogger and receiver of many Dundie Awards. In his free time, Brock enjoys adventuring with his wife, kids, and dogs, while dreaming of retirement.

Related articles