[英]How to add various groups to the computers in OU?
I need to add various applications groups to the computers in an OU, that will be pushed out later. 我需要将各种应用程序组添加到OU中的计算机,稍后将推出。 In AD, I go to OU, right click on the respective computer and click properties and then go to "member of" tab, and then add the various groups. 在AD中,我转到OU,右键单击相应的计算机,然后单击属性,然后转到“成员”选项卡,然后添加各个组。
How can I automate these steps using PowerShell, so that it will apply these groups to all the computers in that OU? 如何使用PowerShell自动执行这些步骤,以便将这些组应用于该OU中的所有计算机?
import-module ActiveDirectory
$allComputers = @()
$ADgroup = "Computer Policy Application Group"
$theOU = [ADSI]"LDAP://OU=AnOU,DC=some,DC=test,DC=com"
foreach ($item in $theOU.psbase.Children) {
if ($item.ObjectCategory -like '*computer*') {
$allComputers += $item.Name
}
}
foreach ($pc in $allComputers) {
Add-ADGroupMember $ADgroup $pc
}
Then of course, you can add more groups, or setup an array of groups and iterate through it adding as you go... This will throw a lot of errors if the computer is already part of the group, by the way. 然后,当然,您可以添加更多的组,或设置组的数组并在添加过程中进行迭代以添加它...如果计算机已经属于该组,这将引发很多错误。
If you are using server2008 or newer (or have the required components installed) this is the simplest solution I have found. 如果您使用的是server2008或更高版本(或安装了必需的组件),这是我找到的最简单的解决方案。
$groupList=@("group1","group2","group3")
foreach ($Comp in (Get-AdComputer -server $ADServer -searchBase "OU=computers,DC=company,DC=com" -searchscope oneLevel")) {
foreach ($Group in $groupList) { Add-ADGroupMember -Identity $Group -Members $Comp -Server $ADServer }
}
Be sure to populate the $groupList variable with an array of the samaccountnames of the groups you wish to add, and to replace "OU=computers,DC=company,DC=com" with the LDAP Path to the OU containing the computers you wish to add permissions to. 确保用要添加的组的samaccountname的数组填充$ groupList变量,并用包含您希望的计算机的OU的LDAP路径替换“ OU = computers,DC = company,DC = com”向其添加权限。
Using the ActiveDirectory module, you can either user Add-ADPrincipalGroupMember or Add-ADGroupMember. 使用ActiveDirectory模块,您可以使用Add-ADPrincipalGroupMember或Add-ADGroupMember。
The former 'Adds a member to one or more Active Directory groups' whilst the latter 'Adds one or more members to an Active Directory group'. 前者“将成员添加到一个或多个Active Directory组”,而后者“将一个或多个成员添加到Active Directory组”。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.