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.
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:
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:
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:
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:
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.