Copying groups

The following code sample copies a group.

[Reflection.Assembly]::LoadWithPartialName("Softerra.Adaxes.Adsi")

# Connect to the Adaxes service
$ns = New-Object "Softerra.Adaxes.Adsi.AdmNamespace"
$service = $ns.GetServiceDirectly("localhost")

# Bind to the target container
$targetContainerDN = "CN=Users,DC=domain,DC=com"
$targetContainer = $service.OpenObject("Adaxes://$targetContainerDN",`
    $null, $null, 0)

# Copy group
$sourceGroupPath = "Adaxes://CN=SalesGroup,CN=Groups,DC=domain,DC=com"
$newGroupRdn = "CN=My New Group"
$group = $targetContainer.CopyHere($sourceGroupPath, $newGroupRdn)

$group.Put("sAMAccountName","My New Group") # Group Name (pre-Windows 2000)

# Copy group members
$sourceGroup = $service.OpenObject($sourceGroupPath, $null, $null, 0)
$members = $sourceGroup.Get("member")
$group.Put("member", $members)

$group.SetInfo()

See also