PowerShell to get domain expiry
PowerShell (whois) Tuesday, 11 April 2023 by paul

The script below can be used to check for the exiry of a web domain using the WHOIS Domain Rest API from https://www.ip2whois.com/developers-api

# get-domainexpiry.ps1 - Get Domain Expiry
# usage: get-domainexpiry.ps1 apikey domainname
# eg get-domainexpiry.ps1 45345345345345 google.com


$url = "https://api.ip2whois.com/v2?key=$API&domain=$domain"

try {
	$results = (Invoke-RestMethod -uri $url)
} catch {
    Write-Host "StatusCode:" $_.Exception.Response.StatusCode.value__ 
    Write-Host "StatusDescription:" $_.Exception.Response.StatusDescription	

$expirydate = $results.expire_date
$ed = [datetime]$expirydate
$ts = New-TimeSpan -Start (Get-date).tostring() -End $ed
$days = $ts.Days
Write-Host $days":"$expirydate

There is a free tier, at https://www.ip2whois.com/developers-api, which allows 500 lookups per month. If you need more then you can pay.

Add Comment
No Comments.