Skip to content

Get your public IP in PowerShell

One line: (irm ipconfig.io).Trim() returns your public IP as a clean string, and irm ipconfig.io/json returns a fully parsed object with location, ISP and ASN — no JSON wrangling, because Invoke-RestMethod does it for you. PowerShell users are one of the largest client families we see at ipconfig.io, so this guide covers the idioms properly: the one-liners, the object form, a change monitor, and the etiquette of polling a free service.

Maintained by the ipconfig.io team · Reviewed 1 July 2026

The one-liners

powershell
# Just the IP (Trim strips the trailing newline):
(Invoke-RestMethod ipconfig.io).Trim()

# Same, with the alias:
(irm ipconfig.io).Trim()

# A single field, as plain text:
(irm ipconfig.io/country).Trim()
(irm ipconfig.io/asn-org).Trim()

Works identically in Windows PowerShell 5.1 and PowerShell 7+. (The classic ipconfig command can't do this — it lists your adapters' private LAN addresses; the public address only exists from the internet's point of view, so you have to ask a server what it sees.)

The object form — location, ISP, everything

Invoke-RestMethod auto-parses JSON into a PSCustomObject, which makes the full record the more PowerShell-native call:

powershell
$r = irm ipconfig.io/json

$r.ip          # 203.0.113.42
$r.country     # Australia
$r.city        # Sydney
$r.asn         # AS13335
$r.asn_org     # Your ISP's name
$r.hostname    # Reverse-DNS name, when one exists

Pipe it around like any object — irm ipconfig.io/json | Select-Object ip, country, asn_org, export it with ConvertTo-Json, or check any address's record with irm "ipconfig.io/json?ip=1.1.1.1". Field-by-field reference: the API docs. If a value surprises you — wrong city is common — that's geolocation accuracy, not a parsing problem.

A change monitor in ten lines

The practical reason PowerShell asks for its public IP is usually "tell me when it changes" — home connections rotate (static vs dynamic), and anything pointing at your address breaks silently when they do:

powershell
$file = "$env:USERPROFILE\last-ip.txt"
$now  = (irm ipconfig.io).Trim()
$last = if (Test-Path $file) { Get-Content $file } else { "" }

if ($now -ne $last) {
    Set-Content $file $now
    Write-Host "Public IP changed: '$last' -> '$now'"
    # notify however you like: mail, webhook, toast...
}

Register it with Task Scheduler (schtasks or a New-ScheduledTaskTrigger every 15–30 minutes) and you have the Windows twin of our cron-based monitoring guide, which also covers the notify-me options.

Etiquette (please)

A gentle note from the operators' side: a surprising amount of traffic to this service is PowerShell polling in tight loops. Your public IP changes at most a few times a day — once every 15–30 minutes is plenty, and aggressive per-second loops just meet the rate limiter. Cache the last value (as above), back off on failure, and one free request at a time will always be here for you.

Frequently asked questions

Public IP in PowerShell?(irm ipconfig.io).Trim() — one line, both PowerShell 5.1 and 7+.

Location and ISP too?$r = irm ipconfig.io/json, then $r.country, $r.city, $r.asn_org — parsed for you.

irm vs iwr?Invoke-RestMethod parses the body (object/string) — right for this. Invoke-WebRequest wraps status and headers; the text lands in .Content.

Why doesn't ipconfig show it? It lists private adapter addresses; the public IP is only visible from the internet side.

Next steps

Geolocation by MaxMind GeoLite2. No tracking, no keys.