Error message "The User Profile Application requires domain credentials for connection access" when trying to add a Windows group to the User Profile Service Application connection permissions

A customer had a problem with the User Profile Service Application in SharePoint 2013 on premise. It was not possible to add a Windows Group in the connection permission dialog and save the changes. Right after clicking the OK button the following error message appeared:

Sorry, something went wrong

The User Profile Application requires domain credentials for connection access

I was not able to find the root cause of the problem but I was able to add the Windows group through a PowerShell script I found at Waldek Mastykarz website:

https://blog.mastykarz.nl/granting-permissions-user-profile-service-application-powershell

The script was original written for SharePoint 2010 but it also works with SharePoint 2013. It modified the original script a little bit and attached it to this post.

 

Grant-UserProfileConnectionPermission.zip