Skip to content

Instantly share code, notes, and snippets.

@DarthJahus
Created November 2, 2017 23:52
Show Gist options
  • Save DarthJahus/b4eeef67b77da99d500eab90dd4d87c0 to your computer and use it in GitHub Desktop.
Save DarthJahus/b4eeef67b77da99d500eab90dd4d87c0 to your computer and use it in GitHub Desktop.
Whois command for PowerShell
<#
.SYNOPSIS
Domain name WhoIs
.DESCRIPTION
Performs a domain name lookup and returns information such as
domain availability (creation and expiration date),
domain ownership, name servers, etc.
.PARAMETER domain
Specifies the domain name (enter the domain name without http:// and www (e.g. power-shell.com))
.EXAMPLE
WhoIs -domain power-shell.com
whois power-shell.com
.NOTES
File Name: whois.ps1
Author: Nikolay Petkov
Blog: http://power-shell.com
Last Edit: 12/20/2014
Made by: KornKolio (https://gallery.technet.microsoft.com/WHOIS-PowerShell-Function-ed69fde6)
Add it to your $profile, line: . PATH\whois.ps1
Or dot-source it: . PATH\whois.ps1
You may need to Set-ExecutionPolicy
.LINK
http://power-shell.com
#>
Function WhoIs {
param (
[
Parameter(
Mandatory=$True,
HelpMessage='Please enter domain name (e.g. microsoft.com)'
)
]
[string]$domain
)
Write-Host "Connecting to Web Services URL..." -ForegroundColor Green
try {
# Retrieve the data from web service WSDL
If ($whois = New-WebServiceProxy -uri "http://www.webservicex.net/whois.asmx?WSDL") {
Write-Host "Ok" -ForegroundColor Green
}
else {
Write-Host "Error" -ForegroundColor Red
}
Write-Host "Gathering $domain data..." -ForegroundColor Green
# Return the data
(
($whois.getwhois("=$domain")).Split("<<<")[0]
)
}
catch {
Write-Host "Please enter valid domain name (e.g. microsoft.com)." -ForegroundColor Red
}
}
# end function WhoIs
@ninad29690
Copy link

Getting error on creating web service reference New-WebServiceProxy : The HTML document does not contain Web service discovery information

@jvhconsulting
Copy link

I'm getting the same error message. seems a few different scripts out there point to the same webproxy but they fail:
New-WebServiceProxy : The underlying connection was closed: The connection was closed unexpectedly.
At C:\scripts\whois3.ps1:43 char:16

Ideas?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment