Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Adding deployment admins via powershell error

Posted on by 1,747

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

  • Kokulan Profile Picture
    Kokulan 18,048 on at
    RE: Adding deployment admins via powershell error

    Thanks for sharing the solution

  • Verified answer
    Jarrod Williams Profile Picture
    Jarrod Williams 1,747 on at
    RE: Adding deployment admins via powershell error

    The solution on this had more to do with the output of the script in the compare than anything else.  When I compared the text output of the script I noticed that there were trailing spaces on some of the names where there wasn't on the ones going through and when I put them into the file manually (without  spaces) it worked fine.  

    Resolution was to use a trimend () on the variable to clip white space off the end and then it added the admins without issue.  

  • Jarrod Williams Profile Picture
    Jarrod Williams 1,747 on at
    RE: Adding deployment admins via powershell error

    Hi Kokulan,

    Yep, for the adds I'm pulling from Get-ADGroupMember and getting the domain and SAM name from that.  

    Also, for the accounts I'm getting errors with, if I just manually enter the name and not use any sort of variable it works fine.  

  • Kokulan Profile Picture
    Kokulan 18,048 on at
    RE: Adding deployment admins via powershell error

    You might have already tried but just wanted to check if you tried including the correct domain for the user using sam account?

    6102.ScreenClip-_5B00_170_5D00_.png

    I remember a while ago, I had to use  domainname.local  for it to recognise the user so not sure if you have already tried that

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,214 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans