PowerShell: Get Public IP Address
Need to check a machine's public (external) IP address - for remote access setup, whitelisting, or confirming what address you're browsing from? This one-liner fetches it from an external service.
Prerequisites:
- Privileges: None
- Module: Built-in, no import needed
Quick Command:
Invoke-RestMethod -Uri "https://api.ipify.org"
Example Output:
203.0.113.42
📦
Want all of them at once?
Get every free one-liner from this blog in a single downloadable bundle organized by category, each with full comment-based help. No more copy-pasting one at a time.
Get every free one-liner from this blog in a single downloadable bundle organized by category, each with full comment-based help. No more copy-pasting one at a time.
How It Works:
- Invoke-RestMethod sends a web request and returns the response - unlike local system queries (CIM/WMI), your public IP isn't stored anywhere on the machine itself, since it's assigned by your ISP at the network level, not by your computer.
- -Uri "https://api.ipify.org" points to a free, simple API that returns nothing but your current public IP address as plain text.
- Since the service returns just the raw IP with no extra formatting, no Select-Object or parsing is needed - the output is already exactly what you want.
Pro Tip:
This requires an active internet connection to work, unlike the local IP address lookup - if there's no internet access, this command will fail or time out.