How to Get Your Public IP Address Using PowerShell (2025 Guide)

Time: 2025.07.03 07:43Author: petro

If you're using a Windows PC and want to find out your current public IP address—the one your system uses to access the internet—you can easily do this using PowerShell.

Several online services are available that return your public IP address in plain text or JSON format. You can query these services directly from PowerShell with a single command.

Quick PowerShell Command to Get Your Public IP

One of the easiest ways to retrieve your public IP is by using the Invoke-WebRequest cmdlet to access an external IP-checking service:

powershell
 
(Invoke-WebRequest -Uri "http://ifconfig.me/ip").Content

Or a shorter alternative:

powershell
 
(curl ifconfig.me).Content

This will return your public IP address directly in the PowerShell console.

 Other IP Services You Can Use

Here are a few reliable websites that return your IP address in a plain-text format:

You can replace the URL in your PowerShell command with any of these.

 Get GeoIP Information (Location, City, GPS)

If you want more than just your IP address—like your city, region, postal code, or GPS coordinates—you can use this command with the Invoke-RestMethod cmdlet:

powershell
 
Invoke-RestMethod -Uri ('http://ipinfo.io/' + (Invoke-WebRequest -Uri "http://ifconfig.me/ip").Content)

This returns a JSON object with your GeoIP data.

 Handling Errors on Server Core or IE-Disabled Systems

On systems where Internet Explorer is disabled or uninstalled (like Windows Server Core), the Invoke-WebRequest command may throw an error:

The response content cannot be parsed because the Internet Explorer engine is not available...

To avoid this, use the -UseBasicParsing switch:

powershell
 
(Invoke-WebRequest -UseBasicParsing -Uri "http://ifconfig.me/ip").Content

Or use the legacy WebClient class:

powershell
 
$wc = New-Object System.Net.WebClient $wc.DownloadString("http://myexternalip.com/raw")

 

 Get Public IP Using DNS (via OpenDNS)

You can also find your external IP address using DNS queries. OpenDNS provides a special hostname that always returns your IP:

powershell
 
Resolve-DnsName -Name myip.opendns.com -Server resolver1.opendns.com

Or use the nslookup command from CMD:

cmd
 
nslookup myip.opendns.com resolver1.opendns.com

Note on Public IP Accuracy

Keep in mind that the IP address returned is usually not the local IP of your computer. It’s often the public IP of your router, especially if you're behind a NAT, proxy, or using a dynamic IP from your ISP. It reflects the IP as seen by external services.

MethodCommand
Basic PowerShell(Invoke-WebRequest -Uri "http://ifconfig.me/ip").Content
With curl(curl ifconfig.me).Content
GeoIP LookupInvoke-RestMethod -Uri ('http://ipinfo.io/'+(Invoke-WebRequest -Uri "http://ifconfig.me/ip").Content)
Legacy WebClient$wc = New-Object System.Net.WebClient; $wc.DownloadString("http://myexternalip.com/raw")
DNS via OpenDNSResolve-DnsName -Name myip.opendns.com -Server resolver1.opendns.com

Now you have multiple ways to check your public IP address using PowerShell, whether you need a quick check or full location data.