簡體   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