I needed a quick way to determine the external-facing IP of a remote system. As long as you’re not going through a proxy, you can use sites like whatismyip.com or type “my IP address” into Google. I wanted to achieve this without having to get onto the machine and fire up the web browser.
The following one-liner will query the whatismyip.org API from a remote system, and return just the IP:
Invoke-Command -ComputerName <remote PC name> -ScriptBlock {(Invoke-RestMethod -Uri "http://www.realip.info/api/p/realip.php").IP}