The script :
$sourceUserDNParamName = "param-User" # TODO: modify me
$replaceGroups = $True # TODO: modify me
# Bind to the source user
$sourceUserDN = $Context.GetParameterValue($sourceUserDNParamName)
$sourceUser = $Context.BindToObjectByDN($sourceUserDN)
# Get groups to add
$groupGuidsToAdd = New-Object "System.Collections.Generic.HashSet[System.Guid]"
$sourceUser.GetEx("adm-DirectMemberOfGuid") | %%{[void]$groupGuidsToAdd.Add([Guid]$_)}
# Get current groups
$currentGroupGuids = New-Object "System.Collections.Generic.HashSet[System.Guid]"
$Context.TargetObject.GetEx("adm-DirectMemberOfGuid") | %%{[void]$currentGroupGuids.Add([Guid]$_)}
# Update groups
foreach ($guidBytes in $groupGuidsToAdd)
{
$guid = [Guid]$guidBytes
if ($currentGroupGuids.Remove($guid))
{
continue
}
$group = $Context.BindToObjectEx("Adaxes://<GUID=$guid>", $True)
$group.Add($Context.TargetObject.AdsPath)
}
if ($replaceGroups)
{
# Get the primary group ID
$primaryGroupId = $Context.TargetObject.Get("primaryGroupID")
foreach ($guidBytes in $currentGroupGuids)
{
$guid = [Guid]$guidBytes
$group = $Context.BindToObjectEx("Adaxes://<GUID=$guid>", $True)
# Skip the group if it is the user's Primary Group
if ($group.Get("primaryGroupToken") -eq $primaryGroupId)
{
continue
}
$group.Remove($Context.TargetObject.AdsPath)
}
}
Variable:
The Form:
The Error:
Create User Copy Groups2: 1 operation executed
Run PowerShell script 'Copy Groups' for the user
Exception calling "BindToObjectByDN" with "1" argument(s): "'adm-InitiatorDN' is unavailable." Stack trace: at <ScriptBlock>, <No file>: line 6
You cannot call a method on a null-valued expression. Stack trace: at <ScriptBlock>, <No file>: line 10