Get your public IP using PowerShell

Quick and simple one liner to get your public IP using Powershell via the code below

(Invoke-WebRequest -uri “https://www.theictguy.co.uk/ip/”).Content

You can take this one step further and have the script output to a text file My_Public_IP.txt which will be stored in the current working directory

(Invoke-WebRequest -uri “https://www.theictguy.co.uk/ip/”).Content | Out-File $PWD\My_Public_IP.txt

This can be taken even further to identify when your public IP Address has changed, set this as a start-up script and it will notify you on start-up.

Get your public IP using PowerShell
$MyCurrentIP = (Invoke-WebRequest -uri "https://www.theictguy.co.uk/ip/").Content
$MyPreviousIP = Get-Content $PWD\My_Public_IP.txt
if($MyCurrentIP -eq $MyPreviousIP) {
write-host "Your IP Address has not changed"
} else {
(Invoke-WebRequest -uri "https://www.theictguy.co.uk/ip/").Content | Out-File $PWD\My_Public_IP.txt
$ButtonType = 0
$Timeout = 60
$Confirmation = New-Object -ComObject wscript.shell
$Confirmation.popup("Your IP Address has changed to $MyCurrentIP. New IP Address written to My_Public_IP.txt",$Timeout,"Public IP has changed",$ButtonType)
}

If you found this article helpful, would you consider buying me a Coffee?