Hello,
Sorry for a delayed reply. The thing is that removing a user from a group is a sensitive operation, and the Remove-AdmPrincipalGroupMembership cmdlet always prompts for confirmation of this operation. This works well when you call the cmdlet from the PowerShell Console or PowerShell ISE, however, currently, Adaxes does not support prompting for user input from PowerShell scripts run by Business Rules, Custom Commands and Scheduled Tasks. Thus, when the cmdlet attempts to show the confirmation prompt, you get the error message.
To workaround this, you need to disable the confirmation. For this purpose, when calling the cmdlet from your script, you need to set the -Confirm parameter of the cmdlet to false. For this purpose, find the following line in your script:
Remove-AdmPrincipalGroupMembership -Identity $UserDN -MemberOf $dg
and append -Confirm:$False:
Remove-AdmPrincipalGroupMembership -Identity $UserDN -MemberOf $dg -Confirm:$False
This should do the job.