我在 Powershell 中有这样的功能。当用户为任何参数传递空字符串时,powershell 会验证并引发异常。我该如何处理此类异常?
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
}
}