I have a function like this in Powershell. When the user passes a null string for any of the parameters, powershell validates and raises exception. How do I handle such exceptions ?
function CheckADUser()
{
param(
[ValidateLength(1,256)]
[string]$domainName,
[ValidateLength(1,256)]
[string]$username,
[ValidateLength(1,256)]
[string]$password)
Process{
$fullyQualifiedUser = $domainName+"\"+$username
$domain = New-Object DirectoryServices.DirectoryEntry("", $fullyQualifiedUser, $password)
return $domain.name
}
}