我正在尝试创建一个 powershell 函数来检查活动目录 OU 是否存在,并让它返回一个 true 或 false 值,以便与另一个函数一起使用来创建用户。我遇到的问题是它总是返回一个错误值,即使 OU 存在。
function checkIfOuExists{
param(
[parameter(Mandatory)]
[string]$nameOfOU
)
$existingOU = Get-ADOrganizationalUnit -Filter 'Name -like "$nameOfOU"'
if($existingOU -eq $null){
return $false
}
else{
return $true
}
}