繁体   English   中英

具有多个 OU 的 AD 中的新用户

[英]New User in AD with multiple OUs

我的第一篇文章在这里。

所以事情是这样的,

最终目标是将新用户放置在特定的 OU 中,以其可分辨名称作为路径。 我可以通过一个后续的 OU 选择来解决这个问题,但是一旦有多个,我想避免后续的脚本编写,因为后续的 OU 的数量可能会改变。

有没有人知道如何创建一个循环或任何其他解决方案,这些解决方案将继续通过 OU 的每一层询问我,直到选择所需的 OU。

例如,用户将在 state IL 下在美国被聘为安全人员,在芝加哥市我的 OU 配置如下:US IL Chicago Safety Users

我希望脚本循环遍历每一层,直到我选择了用户或我喜欢的参数。 请注意,每个后续 OU 都会有多个选择,我想在网格中对这些选择进行排序和选择。 我已经知道这部分,但对我来说棘手的是创建该循环。

对 powershell 上的 While Do Until 不是很熟悉。

我会做我的研究,但会感谢任何建议。 它不一定是循环,但我正在寻找使用 $ 而不是确定参数的解决方案。

干杯,

if ($Location -eq $null )
{
[System.Windows.MessageBox]::Show("'You didn't enter the required parameter, script ending'","System Notification","Ok")
 exit
}
if ($Location -ne $null )               
{
while ($Location -ne $null) {
  $DomainOU1=Get-ADOrganizationalUnit -Filter "Name -like '$Location'" -SearchBase $DistinguishedGroupName -SearchScope OneLevel | select Name -ExpandProperty Name
  }
do {
  $Location1=@($DomainOU1) | sort
  $Location1=$Location1 | Out-GridView -Title "Choose Employee Location of Deployment"
  $Location1=$Location
}
Until ($Location -eq "Users")
}
Write-output "You chose $Location"

不是完整的答案,但这看起来有问题:

while ($Location -ne $null) {
  $DomainOU1=Get-ADOrganizationalUnit -Filter "Name -like '$Location'" -SearchBase $DistinguishedGroupName -SearchScope OneLevel | select Name -ExpandProperty Name
  }

它基于$location变量进行循环,但循环中的任何内容都不会更改$location变量,因此它将永远循环。

所以我决定在这种情况下做的是将用户/计算机 OU 添加到所有目标 OU,并按用户过滤 $。

$EmployeeOU=Get-ADOrganizationalUnit -Filter "Name -like 'Users'" -SearchBase (Get-ADDomain).DistinguishedName | select Name,DistinguishedName

$Location=@($EmployeeOU) | sort
$Location=$Location | Out-GridView -Title "Choose Employee Location of Employment" -PassThru

这允许我通过显示 DistinguishedName OU 详细信息将用户放在所需位置。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM