Skip to content

Instantly share code, notes, and snippets.

@bmorrisondev
Last active July 28, 2024 15:47
Show Gist options
  • Save bmorrisondev/f4aef19a1c88d611ee99ad3489d59620 to your computer and use it in GitHub Desktop.
Save bmorrisondev/f4aef19a1c88d611ee99ad3489d59620 to your computer and use it in GitHub Desktop.
Update a Dynamic DNS Record in Namecheap using PowerShell
function Set-NamecheapDdnsRecord {
<#
.SYNOPSIS
Update the IP address of a Dynamic DNS record in Namecheap.
.EXAMPLE
PS C:\> Set-NamecheapDdnsRecord -HostRecord www -Domain brianmorrison.me -ApiKey 12345678abcd -Ip 123.234.123.234
Updates the record for www.brianmorrison.me to 123.234.123.234
.NOTES
Author: Brian Morrison II
Date: 4/10/2019
Website: https://brianmorrison.me
#>
param(
# Host record that will be updated
[Parameter(Mandatory=$true)]
[String]
$HostRecord,
# Domain name in Namecheap
[Parameter(Mandatory=$true)]
[String]
$Domain,
# API Key obtained from the Advanced DNS tab of the domain.
[Parameter(Mandatory=$true)]
[String]
$ApiKey,
# IP that the record will be pointed to. Defaults to the public IP of where function was executed.
[Parameter()]
[String]
$Ip
)
if($null -eq $Ip) {
$ipifyResponse = Invoke-WebRequest -Method Get -Uri "https://api.ipify.org"
$Ip = $ipifyResponse.content
}
$namecheapRequestUri = "https://dynamicdns.park-your-domain.com/update?host=$HostRecord&domain=$Domain&password=$ApiKey&ip=$Ip"
Invoke-WebRequest -Method Get -Uri $namecheapRequestUri
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment