简体   繁体   English

将OU的所有用户也添加到安全组中

[英]Add ALL users of a OU to a security group also the ones in a security group

I want to add all users of my OU into a specific security group. 我想将OU的所有用户添加到特定的安全组中。 I used the command below, which showed me all Users of the OU, but not the ones in a security group. 我使用下面的命令,该命令显示了OU的所有用户,但没有显示安全组中的用户。

So how can I fix my command to show me ALL Users in the OU? 那么,如何解决我的命令以向我显示OU中的所有用户?

GET-ADUser -SearchBase 'OU=OU, DC=DC' -Filter 'enabled -eq $true | % {Add-ADGroupMember 'Security-Group' -Members $_}

That is because you query all users not groups . 那是因为您查询所有用户而不是 If the users inside the security groups are located in a different OU you should also check that OU. 如果安全组内的用户位于另一个OU中,则还应检查该OU。 Or do something like: 或执行类似的操作:

$users = Get-ADUser -SearchBase 'OU=OU, DC=DC' -Filter {(enabled -eq $true)}
foreach($user in $users){
    Add-ADGroupMember 'security-group' -Members $user
}
$groups = Get-ADGroup -Filter * -SearchBase 'OU=OU, DC=DC'
foreach($group in $groups){
    $members = Get-ADGroupMember $group
    foreach($member in $members){
        Add-ADGroupMember 'security-group' -Members $member
    }
}

With the above script, everybody will be added to the security group including users not in that OU but inside a group in that OU. 使用上述脚本,每个人都将添加到安全组,包括不在该OU中但在该OU中的组内的用户。

Hope this helps! 希望这可以帮助!

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

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