This script checks if an Active Directory domain exists. If found it continues. If not it exits the script.
$Domain = Read-Host "Please enter the domain name"
try {
Get-ADDomain -Identity $Domain | Out-Null
Write-Host "[INFO] Domain found. Continuing..."
}
catch [Microsoft.ActiveDirectory.Management.ADIdentityNotFoundException] {
Write-Host "[ERROR] Domain $Domain does not exists. Aborting..."
exit
}