简体   繁体   English

如何将各种组添加到OU中的计算机?

[英]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.

相关问题 如何在AD中循环访问OU以将用户添加到各种安全组? - How can I loop through OU in AD to add users to various security groups? 在每个AD OU中创建AD计算机组 - Creating AD Groups of computers in each AD OU 将用户/计算机的 OU 添加到安全组 - Add OU of users / computers to a security group 如何从计算机 OU 中动态移动计算机帐户 - How to dynamically move computer accounts from Computers OU 需要帮助编写Powershell脚本以在AD用户和计算机>> OU >>分发组中将Extension Attribute 1值更改为“Staff”? - Need help in writing Powershell script to change the Extension Attribute 1 value to ‘Staff’ in AD Users and Computers >> OU >> Distributions groups? 如何使用WMI获取计算机的当前OU并列出该OU中的所有其他计算机? - How do I use WMI to get the current OU of a computer and list all other computers in that OU? 使用foreach将AD计算机添加到组 - Using foreach to add AD computers to groups 将计算机添加到安全组-Powershell GUI? - Add computers to security groups - Powershell GUI? 如何在AD中搜索“计算机” OU中的名称,然后将这些计算机移至正确的位置? - How do i search AD for names like the ones in the “Computers” OU and then move those computers over to their proper location? 从OU检索组 - Retrieve Groups from OU
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM