I'm trying to automate a process to be able to add and remove users as deployment administrators on an automated basis based on a group that is setup within Active Directory. I've got most of it completed however I've run into a CRM specific issue with the users. There are some users who have the same user account name in multiple domains within the same overall forest. The company I work for is currently merging many of these down and for newer users that have only ever been a member of one domain the new-CrmDeploymentAdministrator or remove-CrmDeploymentAdministrator work correctly. However, if the user has been a member of multiple domains within the forest the PowerShell can't find the correct user to associate.
If I run the command against their user explicitly, the command completes without issue, it is only when part of a larger foreach loop where I run into an error message that says: Invalid user name. failed to validate username for given domain. Only existing domain usernames and email addresses are allowed.
The foreach loop looks like this: foreach ($newadmins in $newadmin) { [string] $newadmins = $newadmins New-CrmDeploymentAdministrator -Name $newadmins Write-Output $newadmins - new }
*This post is locked for comments