How to Get an IP Address Using PowerShell in Windows?

As a system administrator, I recently faced an issue where I needed to quickly find the IP addresses assigned to various network interfaces on my Windows servers. It is easy to achieve this using PowerShell. In this tutorial, I will explain how to retrieve IP address information using PowerShell in a Windows environment.

Get IP Address Using PowerShell in Windows

PowerShell allows you to retrieve IP address information quickly with just a few commands, saving time and effort compared to navigating through GUI menus.

To get started with PowerShell IP configuration, you need to open the PowerShell console. You can do this by following these steps:

  1. Press the Windows key + R to open the Run dialog box.
  2. Type “powershell” and press Enter.

Alternatively, you can search for “PowerShell” in the Start menu and click on the Windows PowerShell app.

Retrieve IP Addresses using Get-NetIPAddress

The Get-NetIPAddress cmdlet is a powerful command introduced in Windows Server 2012 R2 that allows you to retrieve IP address configuration information. Here’s how to use it:

  1. Open the PowerShell console.
  2. Type Get-NetIPAddress and press Enter.

This command will display all the IP addresses configured on your system, including IPv4 and IPv6 addresses, along with the associated network interfaces.

The same cmdlet will also work in Windows 11 OS. Here, you can see I executed the PowerShell script, and it displays the IP address details.

Get IP Address Using PowerShell in Windows

Read How to Set Service to Automatic Using PowerShell?

Filter IP Addresses

If you want to filter the output to display only specific IP addresses, you can use the Where-Object cmdlet. For example, to retrieve only IPv4 addresses, use the following command.

Get-NetIPAddress | Where-Object {$_.AddressFamily -eq "IPv4"}

Here is the exact output in the screenshot below:

Retrieve IP Addresses using Get-NetIPAddress

To filter IP addresses based on a specific network interface, you can use the InterfaceAlias property. For example, to get the IP addresses assigned to the “Ethernet” interface, use:

Get-NetIPAddress -InterfaceAlias "Ethernet"

Read Change Windows 11 Desktop Background Color with PowerShell

Format the Output

PowerShell provides various formatting options to customize the output of the Get-NetIPAddress cmdlet. You can use the Format-Table cmdlet to display the output in a tabular format:

Get-NetIPAddress | Format-Table

Here is the exact output in the screenshot below:

Get an IP Address Using PowerShell in Windows

You can also select specific properties to display using the Select-Object cmdlet. For example, to display only the IP address and interface alias:

Get-NetIPAddress | Select-Object -Property IPAddress, InterfaceAlias

Read Rename a Windows Computer Using PowerShell

Get an IP Address Using PowerShell – Example

Let me share a real-world example where using PowerShell to get IP addresses helped me troubleshoot a network connectivity issue.

I was working on a project for a client in New York City when they reported that one of their servers was unable to communicate with other devices on the network. To diagnose the problem, I used PowerShell to retrieve the IP address information of the problematic server.

First, I connected to the server remotely using PowerShell remoting. Then, I ran the following command to get the IP addresses:

Get-NetIPAddress | Where-Object {$_.AddressFamily -eq "IPv4"}

The output revealed that the server had an incorrect IP address configuration. The IP address was outside the expected range for the network segment. Armed with this information, I was able to quickly correct the IP address settings and restore network connectivity for the server.

Conclusion

In this tutorial, I explained how to use PowerShell to retrieve IP address information in a Windows environment. The Get-NetIPAddress cmdlet is used to get IP addresses, allowing you to filter and format the output according to your needs.

You may also like:

100 PowerShell cmdlets download free

100 POWERSHELL CMDLETS E-BOOK

FREE Download an eBook that contains 100 PowerShell cmdlets with complete script and examples.