PowerShell – Query domain name WhoIs

Hi Guys,

I found, after couple of weeks looking for it, a cool API WebSite that provide an API to query WhoIs : webservicex.net.

Once I found out this site I started writing this little PowerShell function to help me serialize all my future actions with this little guy.

Here is the function I wrote for this purpose:
[ps]Function Get-WhoIsInfo {
<#
.SYNOPSIS
Domain name WhoIs

.PARAMETER DomainName
Specifies the domain name

.EXAMPLE
Get-WhoIsInfo -DomainName prudhomme.wtf

.NOTES
Author: Thomas Prud’homme
Blog: https://blog.prudhomme.wtf

.LINK
https://blog.prudhomme.wtf
#>
Param (
[Parameter(
Mandatory = $true,
HelpMessage = ‘Please enter domain name (e.g. prudhomme.wtf)’)
]
[String]$DomainName
)
Begin {}
Process {
try{
$WebUrl = ‘http://www.webservicex.net/whois.asmx/GetWhoIS?HostName={0}’ -f $DomainName

$WebData = Invoke-WebRequest -Uri $WebUrl -ErrorAction Stop
$WhoIsData = ([Xml]$WebData.Content).string.’#text’
New-Object -TypeName PSObject -Property @{
DomainName = $DomainName
WhoIsData = $WhoIsData
}
}
catch{
throw $_
}
}
End {}
}[/ps]