简体   繁体   English

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

[英]New User in AD with multiple OUs

My first post here.我的第一篇文章在这里。

So here is how it goes,所以事情是这样的,

The end goal is to place the New User in the specific OU, under its distinguished name as path.最终目标是将新用户放置在特定的 OU 中,以其可分辨名称作为路径。 I can resolve this with one subsequent OU selections, but once there are multiple, I would like to avoid the subsequent scripting, because the number of subsequent OUs can change.我可以通过一个后续的 OU 选择来解决这个问题,但是一旦有多个,我想避免后续的脚本编写,因为后续的 OU 的数量可能会改变。

Does anyone have an idea how to create a loop or any other solution that will continue to ask me through each layer of OU's until desired OU is chosen.有没有人知道如何创建一个循环或任何其他解决方案,这些解决方案将继续通过 OU 的每一层询问我,直到选择所需的 OU。

For example, User will be employed as Safety in US, under state IL, in city Chicago My OU configuration would be as follows: US IL Chicago Safety Users例如,用户将在 state IL 下在美国被聘为安全人员,在芝加哥市我的 OU 配置如下:US IL Chicago Safety Users

I would like the script to loop through each layer until I've chosen Users, or a parameter to my liking.我希望脚本循环遍历每一层,直到我选择了用户或我喜欢的参数。 Note that each of subsequent OU's would have multiple choices, which I would like to sort and choose within a Grid.请注意,每个后续 OU 都会有多个选择,我想在网格中对这些选择进行排序和选择。 I already know this part, but what's tricky for me is creating that loop.我已经知道这部分,但对我来说棘手的是创建该循环。

Not very familiar with While Do Until on powershell.对 powershell 上的 While Do Until 不是很熟悉。

I will do my research but would appreciate any suggestions.我会做我的研究,但会感谢任何建议。 It doesn't have to be a loop, but I'm looking for a solution with $ instead of a definite parameter.它不一定是循环,但我正在寻找使用 $ 而不是确定参数的解决方案。

Cheers,干杯,

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"

Not a full answer, but this looks problematic:不是完整的答案,但这看起来有问题:

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

It loops based on the $location variable, but nothing in the loop will ever change the $location variable, so it will loop forever.它基于$location变量进行循环,但循环中的任何内容都不会更改$location变量,因此它将永远循环。

So what I've decided to do in this case, is to add Users/Computers OU to all Destination OU's, and filter the $ by Users.所以我决定在这种情况下做的是将用户/计算机 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

This allows me to put the user in desired location by showing me the DistinguishedName OU details.这允许我通过显示 DistinguishedName OU 详细信息将用户放在所需位置。

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

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