New-ADOrganizationalUnit :服务器不愿意处理请求

时间:2021-04-05 15:10:47

标签: powershell

我正在尝试创建一个函数来检查 OU 是否存在,如果不存在,它将在 AD 内创建新的 OU。

但是我收到错误消息“服务器不愿意处理请求”。我认为这可能与我的 -path 有关,但我已经修补了它并且到目前为止还没有任何运气。搜索错误代码的先前结果会产生具有类似问题的代码,但是他们推荐的修复程序没有奏效。

function CreateOU ([string]$name, [string]$path, [string]$description) {
$newOU = "OU=$name,$path"

# Checking if the OU exists
try {
    Get-ADOrganizationalUnit -Identity $newOU | Out-Null
    Write-Verbose "OU '$newOU' already exists."
}
catch [Microsoft.ActiveDirectory.Management.ADIdentityNotFoundException] {
    Write-Verbose "New OU '$newOU has been created'"
    New-ADOrganizationalUnit -Name $name -Path $path -Description $description
}

} CreateOU -name "Groups" -path "DC=ad,DC=example,DC=com" -description "示例说明"

0 个答案:

没有答案