PowerShell One-Liner: Get External IP Address

Need your External IP address? Just use the following in Windows PowerShell 3+ or PowerShell 7+:

1$ip = (Invoke-WebRequest https://ipinfo.io/ip).Content.Trim()

As a bonus, you can also get additional IP information using ipinfo.io's JSON web service.

1# Simple, object-based approach
2$ipinfo = Invoke-RestMethod https://ipinfo.io/json
3$ipinfo.ip
4$ipinfo.hostname
5$ipinfo.city
6$ipinfo.region
7$ipinfo.country
8$ipinfo.loc
9$ipinfo.org

Note: On older Windows PowerShell installations that default to legacy TLS, you may need to enable TLS 1.2 before making HTTPS requests:

1[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12