After my long loved Raspberry Pi died I needed a new way to update my dynamic DNS. I recently discovered the Invoke-WebRequest cmdlet that lets you send and HTTP(S) request and parse pretty much whatever you get in return. My use for this is to keep my site-to-site VPN up and running.
# Script to update FreeDNS and log the output. # Change Path to desired log location and Uri to your Direct or Token URL from FreeDNS $LogPath = "C:\Scripts\Update-FreeDNS.log" $Uri = "http://sync.afraid.org/u/your_token/" # No need to change these - - $Content = (Invoke-WebRequest -Uri $Uri).Content Add-Content -Path $LogPath -Value (Get-Date) -NoNewline Add-Content -Path $LogPath -Value $Content
Your log file will look something like this
12.11.2019 16.03.44No IP change detected for your.dyn.dns with IP 22.214.171.124, skipping update 12.11.2019 17.00.22No IP change detected for your.dyn.dns with IP 126.96.36.199, skipping update 12.11.2019 18.00.18No IP change detected for your.dyn.dns with IP 188.8.131.52, skipping update
Save these files to somewhere that makes sense, for example C:\Scripts.
- Open Task Scheduler select Task Scheduler Library to the left and click Create Task to the right
- Name your task Update-FreeDNS or something else explaining
- You have to check “Run whether user is logged on or not” so if you do not want your credentials to be saved, create a new user and change to that
- On the trigger tab you can create a schedule that suits your needs. I use every hour, but this is totally up to you
- Under actions click New and paste the following
Program/scripts: C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe Add arguments: "C:\Scripts\Update-FreeDNS.ps1"
- At this point we are finished with the necessities, but feel free to click around to see if any options is of your taste
- OK out and you will be asked for your password
- Run the task on demand and see the result in the log file
As always, ask if anything is unclear.