| by Arround The Web | No comments

How to Use PowerShell to Get an IP Address

An IP (Internet Protocol) address is a unique combination of numeric values that identifies a computer connected to the network using internet protocol. PowerShell can retrieve two types of IP addresses on the system “IPv4” and “IPv6”. IPv4 is a 32-bit address while IPv6 is a 128-bit address. Moreover, the former IP address is a numeric dot-decimal notation while the latter one is an alphanumeric hexadecimal notation.

This article will observe methods to retrieve the IP address using PowerShell.

How to Use PowerShell to Get/Retrieve an IP Address?

PowerShell utilizes the “Get-NetIPAddress” cmdlet to obtain the IP address of the system. It utilizes the “-AddressFamily” parameter to get it.

Further examples are provided below to get a better understanding of it.

Example 1: Get the List of IP Addresses and Their Detailed Information
This instance will retrieve the configurations of IPv4 and IPv6 addresses along with their interface using PowerShell.

Get-NetIPAddress

Example 2: Get the “IPv4” IP Address Along With its Configurations of the System Using PowerShell
This example will retrieve the configurations of the “IPv4” IP address:

Get-NetIPAddress -AddressFamily IPv4

In accordance with the above code:

First, specify the “Get-NetIPAddress” cmdlet, add the “-AddressFamily” cmdlet, and assign the value “IPv4”:



Example 3: Get Only “IPv4” IP Address Using PowerShell

This illustration will get the IP address of “IPv4” with the aid of specified parameters:

(Get-NetIPAddress -AddressFamily IPv4 -InterfaceAlias "Ethernet").IPAddress

According to the above code:

First, specify the “Get-NetIPAddress” cmdlet, then write the “-AddressFamily” parameter and assign the value “IPv4” to it.
After that, specify the parameter “-InterfaceAlias” and define the “Ethernet” to it.
Lastly, concatenate the whole code with the “IPAddress” cmdlet to show only the IP address:

Example 4: Get the “IPv6” IP Address Along With its Configurations of the System Using PowerShell
This example will retrieve the configurations of the “IPv6” IP address:

Get-NetIPAddress -AddressFamily IPv6

In accordance with the above code:

First, specify the “Get-NetIPAddress” cmdlet, add the “-AddressFamily” cmdlet, and assign the value “IPv6”:

Example 5: Get Only “IPv6” IP Address Using PowerShell
This illustration will get the IP address of “IPv6” with the aid of specified parameters:

(Get-NetIPAddress -AddressFamily IPv6 -InterfaceAlias "Ethernet").IPAddress

According to the above code:

First, specify the “Get-NetIPAddress” cmdlet, write the “-AddressFamily” parameter, and assign the value “IPv6” to it.
After that, specify the parameter “-InterfaceAlias” and define the “Ethernet” to it.
Lastly, concatenate the whole code with the “IPAddress” cmdlet to show only the IP address:

That’s how you can use PowerShell for getting the IP address in PowerShell.

Conclusion

The IP address in PowerShell can be retrieved using the “Get-NetIPAddress” cmdlet. In order to get the IP address of “IPv4”, first, add the “Get-NetIPAddress” cmdlet, specify the “-AddressFamily”, and specify the “IPv4” value. Similarly, in order to get the “IPv6” then specify it to the “-AddressFamily” parameter. This blog has discussed a method to get an IP address.

Share Button

Source: linuxhint.com

Leave a Reply