PowerShell for DDNS (DynDNS.org)

I’ll just leave this here. I realise many would prefer alternatives to using scheduled tasks such as Windows services or built-in methods from more advanced routers (as I do) but I had a need to write PowerShell to run every hour and update a DynDNS domain if the current IP doesn’t match the DNS IP.

If you’re running this as a scheduled task, you must do it under the context of the same user that creates the credential file.PrtScr capture

Hope it’s useful for you.

-Lewis

6 thoughts on “PowerShell for DDNS (DynDNS.org)”

  1. Hey lewis, this is exactly what I needed but I’m not familiar with powershell so I was wondering if I could pick your brain a bit. Especially the part where you are getting the credentials for the update. Not sure what to do about the .xml part.

    Please e-mail me if you have time to discuss further.

    Thanks

  2. Hi Jay, I appreciate PowerShell can be very daunting to a new user but fear not, it’s fairly simple.

    The script itself is executed as a specific user on a specific computer so first experiment by simply opening the PowerShell console. You can use the Integrated Scripting Environment (ISE) or the console, but starting new, I would recommend you use the ISE.

    At the prompt, type Get-Credential (uppercase or lowercase doesn’t matter) and press Enter. You’ll be prompted to enter a username and password. Type in anything you want (you’re testing) and press enter or click OK and you’ll see something appear on the command line with the username you entered and a value System.Security.SecureString. What you’ve done is created an “object”. Now, instead of sending that object to the console, you use the “pipe” (vertical character) to “pipe” the object to another command called Export-Clixml.

    Do the same thing but this time type:

    Get-Credential | Export-Clixml "mypassword.xml"
    

    Enter your username and password (again, it can be anything at all, you’re only testing) and press Enter.

    A file called mypassword.xml will be saved in to the path you are curently in – if you haven’t changed it since opening ISE, this will be C:\Users\[username]

    Navigate to that path and you’ll see the file. Open it in Notepad and you’ll see your username and lots of other XML. The “password” you entered is encrypted and only readable by the user who created it.

    Now, applying what you just learned, and using the commands from my script, execute:

    Get-Credential | Export-Clixml "DynDNS-$env:COMPUTERNAME.xml"
    

    In the prompt, enter the username and password you would use to log on to DynDNS and press Enter. A file called DynDNS-[The Name Of Your PC].xml will be created. Keep this XML file with the script (on the same PC you used when creating it!) and then run the script, not forgetting to update the host names you want to update with your current IP.

    Hope that helps!

  3. Great post, thank you for sharing. I needed a script to send my local IP (not internet-facing IP) to the service and this worked great with a few small tweaks.

  4. Hey lewis, this is exactly what I need. But I keep getting “badauth” error everytime I send RestMethod, have double checked the username and password. If I copy the URL into a web browser it works fine.

    Please e-mail me if you have time to discuss further.

    Thanks

  5. Hemant, you may need to provide your credentials in a specific format. For example if you’re using only a friendly user name, try using an email address instead or vice versa. There is a small possibility that Dyn have changed how you interact with their Rest endpoint but I’d be surprised if that were the case. It’s almost definitely just the username or password being incorrect.

Leave a Reply

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