【发布时间】:2021-07-23 01:31:12
【问题描述】:
我们有一个 Powershell 脚本,可以创建新的学生帐户,对现有帐户进行必要的更改,并将帐户移动到基于学校的正确 OU。该脚本之前运行良好,因为 OU 结构非常平坦。所有学校 OU 都直接位于“District Student Users” OU 之下。
学区学生用户
- OMS
- 职业健康与安全
- OES
但是,现在我们正在建立不符合结构的新学校。我们添加了一些需要子 OU 的学校,而不是独立学校级别。 (在 CompilationSchools 下注明)。 *edit-在“AHS”和“BHS”指示的 THS 下添加了额外级别的 OU
- 学区学生用户
- -----OMS
- -----OHS
- -----OES
- -----编译学校
- ---------TMS
- ---------THS
- ----------AHS
- ----------BHS
- ---------TES
脚本将基础 OU 定义为 $base = "OU="+$ou+",OU=District Student Users,DC=district,DC=edu"
我不知道如何在脚本中包含必要的子 OU,同时又不会弄乱现有的基本 OU 定义。
# Move AD Object to the new OU
IF ($newschool -eq 1) {
Switch ($department)
{
"One Middle School" { $ou="OMS" }
"One High School" { $ou="OHS" }
"One Elementary" { $ou="OES" }
default { $ou="z_Unclassified" }
}
Write-Host " Also moved from"$exist.department"to"$department`r
$base = "OU="+$ou+",OU=District Student Users,DC=district,DC=edu"
Sleep 2
Move-ADObject -Identity $dn -TargetPath $base -server $dc }
ELSEIF ($newschool -eq 2) {
Write-Host " Account moved to z_DisabledAccounts OU"`r
$base = "OU=z_DisabledAccounts,OU=District Student Users,DC=district,DC=edu"
Sleep 2
Move-ADObject -Identity $dn -TargetPath $base -server $dc
}
【问题讨论】:
标签: powershell active-directory