I was searching easier way to get notified when dynamic public IP address changes. I’ve create small PowerShell script that sends email notification to list of users or distribution groups when public IP address changes. ZIP file contains PS1 file and TXT file along with Task Scheduler import XML file.

You will extract all three files into "C:\Windows\IPchangeNotification'" folder. You also need to know your email server’s SMTP address and port number along with your username and password to send email out. Please edit variables in PS1 file and import the schedule task XML file in the Task Scheduler.



$scriptpath = $MyInvocation.MyCommand.Definition  
[string]$dir = Split-Path $scriptpath   
set-location $dir 
$oldip = gc .\ip.txt 
Write-Host "Your previous IP was: $oldip" 
$currentip = (New-Object net.webclient).downloadstring("http://api.ipify.org"while ($currentip -eq '') {$currentip = (New-Object net.webclient).downloadstring("http://api.ipify.org")} 
Write-Host "Your current IP is: $currentip" 
$smtpServer = "smtp.mail.com" 
$sender = "sender@mail.com" 
$users = "user1@gmail.com""user2@hotmail.com"$subject = "Your IP $currentip"  
$body = "Previous IP was $oldip"  
if ($oldip -ne $currentip) { 
    foreach ($user in $users) { 
    Write-Host "Sending email notification to $user" -ForegroundColor Green 
    $smtp = New-Object Net.Mail.SmtpClient($smtpServer, 587)  
    $smtp.EnableSsl = $true  
    $smtp.Credentials = New-Object System.Net.NetworkCredential("sender@email.com""password");  
$currentip | Out-File .\ip.txt -Force 
Write-Host "New IP saved in file is: $currentip"