Skip to content

Copying groups

The following code sample copies a group.

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

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

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

# Copy group
$sourceGroupPath = "Adaxes://CN=SalesGroup,CN=Users,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 = $admService.OpenObject($sourceGroupPath, $NULL, $NULL, 0)
$members = $sourceGroup.Get("member")
$group.Put("member", $members)

$group.SetInfo()

See also