PowerShell One-Liner: Get External IP Address

Need your External IP address? Just use the following in PowerShell 3 and above

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

Chrissy is a Cloud and Datacenter Management & Data Platform MVP who has worked in IT for over 20 years. She is the creator of the popular SQL PowerShell module dbatools, holds a master's degree in Systems Engineering and is coauthor of Learn dbatools in a Month of Lunches. Chrissy is certified in SQL Server, Linux, SharePoint and network security. You can follow her on Twitter at @cl.

Posted in PowerShell
5 comments on “PowerShell One-Liner: Get External IP Address
  1. Ben says:

    If you want just the IP there’s no need to parse the JSON response, just request http://ipinfo.io/ip instead

    • Chrissy LeMaire says:

      Ha! Even better. Thanks, Ben!

      I saw you are from ipinfo.io. Would it be possible to remove the carriage return (or whatever that is) so that trim() is not needed?


  2. Grey Panther says:

    There is also http://curlmyip.com/ for just a plain, simple IP.

    • Chrissy LeMaire says:

      Cute URL! I was hoping that wouldn’t have extra white space but alas, that one too returns the same thing as ipinfo.

  3. David Sanborn says:

    You can also use: Invoke-RestMethod http://ipinfo.io/json

    The command output will already give us the location.

    Extracted from: https://www.sysadmit.com/2019/01/windows-saber-ip-publica-PowerShell.html

Leave a Reply

Your email address will not be published. Required fields are marked *