Created
October 17, 2022 20:47
-
-
Save derekantrican/53c77e49973bae654e88686599c04ef8 to your computer and use it in GitHub Desktop.
An example to call the NameCheap API via powershell (and parse the result)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This is just an example for the Get Hosts endpoint | |
# docs: https://www.namecheap.com/support/api/methods/domains-dns/get-hosts/ | |
function GetNamecheapTarget | |
{ | |
param | |
( | |
[string]$username, | |
[string]$apiKey, | |
[string]$domain, | |
[string]$domainHost, | |
[string]$clientIp | |
) | |
$command = 'namecheap.domains.dns.getHosts' | |
$response = Invoke-WebRequest -uri "https://api.namecheap.com/xml.response?ApiUser=$username&ApiKey=$apiKey&UserName=$username&ClientIp=$clientIp&Command=$command&SLD=$domain&TLD=com" | |
return (([xml]$response.Content).ApiResponse.CommandResponse.DomainDNSGetHostsResult.host | Where {$_.Name -eq $domainHost}).Address | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment