powershell - 如何在 AD 中的所有 OU 中创建安全组
问题描述
在我的任务中,有必要根据 OU 名称创建组,同时考虑到嵌套。
比如有这样一个OU
OU=Credential,OU=DepIT,DC=Contoso,DC=loc
那么我需要创建以下组:
在
DepIT
: 三组DepIT_R
,DepIT_W
,DepIT_L
在
Credential
:两组DepIT_Credential_R
,DepIT_Credential_W
最后,DepIT_Credential_R
并且DepIT_Credential_W
必须是 的成员DepIT_L
。
现在结构如下: OU DepIT
,其中 OU Credential
。我准备了我想做的截图:
到目前为止我的尝试:
$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")"
}
}
}
非常感谢您的帮助。
解决方案
推荐阅读
- php - 带有 Nginx 的 Symfony 3.4 上的 CSRF 令牌无效
- android - 为不同的构建类型和产品风格添加不同配置的正确方法
- python - 在 jupetyr 笔记本中导入后如何拆分 csv 文件的列?
- mysql - 在两个表之间执行连接以将国家/地区映射到表 1 中的每个 URL
- git - 完成 git 分支后的标准做法是什么?
- c++ - 如何将 argv[1] 转换为 LPCVOID?
- python - 使用numpy“旋转”数组排序
- python - 在简单的装饰器上找不到 pytest 固定装置,仅在 Python 3 上
- ruby - 如何使用 Ruby 和 Gitlab 优化占用的内存
- javascript - 无法处理子组件中传递的数组