0

在我的任务中,有必要根据 OU 名称创建组,同时考虑到嵌套。

比如有这样一个OU

OU=Credential,OU=DepIT,DC=Contoso,DC=loc

那么我需要创建以下组:

  • DepIT: 三组DepIT_R, DepIT_W,DepIT_L

  • Credential:两组DepIT_Credential_RDepIT_Credential_W

最后,DepIT_Credential_R并且DepIT_Credential_W必须是 的成员DepIT_L

现在结构如下: OU DepIT,其中 OU Credential。我准备了我想做的截图:

1. DepIT - 结构

2. DepIT - 结构和组

3. 凭证 - 组

4. DepIT_L 组成员

到目前为止我的尝试:

$OU = "OU=DepIT,DC=Contoso,DC=loc"
$one_level_OU = Get-ADOrganizationalUnit -SearchBase $OU -SearchScope OneLevel -filter *


$one_level_OU | 

foreach{

New-ADGroup -Name $($_.Name+"_RW") -GroupCategory Security -groupscope global -Path $_.DistinguishedName
New-ADGroup -Name $($_.Name+"_R") -GroupCategory Security -groupscope global -Path $_.DistinguishedName
New-ADGroup -Name $($_.Name+"_L") -GroupCategory Security -groupscope global -Path $_.DistinguishedName

    $ous = Get-ADOrganizationalUnit -SearchBase "OU=$($_.name),OU=DepIT,DC=Contoso,DC=loc" -SearchScope Subtree -filter "name -notlike '*$($one_level_OU.Name)*'"

    $group_L = get-adgroup -Filter "name -like '*_L'" -Properties * | select name

    $ous | foreach {

       New-ADGroup -Name $($_.Name+"_RW") -GroupCategory Security -groupscope global -Path $_.DistinguishedName
       New-ADGroup -Name $($_.Name+"_R") -GroupCategory Security -groupscope global -Path $_.DistinguishedName


       foreach ($gr in $group_L) {
            Add-ADGroupMember -Identity $($_.name) -Members "$($_.Name+"_RW")", "$($_.Name+"_R")"
       }
    }
}

非常感谢您的帮助。

4

0 回答 0