I would like to add a group to members of another group using PowerShell. I have seen a way to do that with vbscript but is it possible to do it with powershell?

My environment:
-Windows Server 2008 R2
-PowerShell 2.0

有帮助吗?

解决方案

One way is using ActiveDirectory module:

Import-Module ActiveDirectory

Add-ADGroupMember -Identity <samaccountname of destination group> -Members <samaccountname of group to add in>

其他提示

This script copies the group members inside another specified group

$Source_Group = "CN=SourceGroupName,OU=Groups,DC=domain,DC=com"
$Destination_Group = "CN=DestinationGroupName,OU=Groups,DC=domain,DC=com"

$Target = Get-QADGroupMember $Source_Group
foreach ($Person in $Target) {
    add-QADGroupMember -identity $Destination_Group -member $Person.dn
}

Source

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top