Using the PowerShell script to add user to a group in AD

If there are multiple DC then you need to pass on which DC the user has been created.

Extract createdOnServer attribute from resultObject and server as parameter to below command -

Add-ADGroupMember -Identity $GroupName -Members $Username -Server <Value of created on server Name>