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.
One of the easiest ways to retrieve your public IP is by using the Invoke-WebRequest
cmdlet to access an external IP-checking service:
Or a shorter alternative:
This will return your public IP address directly in the PowerShell console.
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.
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:
This returns a JSON object with your GeoIP data.
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:
Or use the legacy WebClient
class:
You can also find your external IP address using DNS queries. OpenDNS provides a special hostname that always returns your IP:
Or use the nslookup
command from CMD:
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.
Method | Command |
---|---|
Basic PowerShell | (Invoke-WebRequest -Uri "http://ifconfig.me/ip").Content |
With curl | (curl ifconfig.me).Content |
GeoIP Lookup | Invoke-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 OpenDNS | Resolve-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.