CRM : Cannot Add new users

If you are running CRM locally and you try and add a new user and you get this error:

Unhandled Exception: System.ServiceModel.FaultException`1[[Microsoft.Xrm.Sdk.OrganizationServiceFault, Microsoft.Xrm.Sdk, Version=8.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]]: Server was unable to process request.Detail:
  -2147016646
  Server was unable to process request.
  2017-08-25T10:49:59.5445312Z
 
 


 The error here is this section:

-2147016646

This is a domain controller error which says the server is not operational, which is weird as people can login but new users cannot be added - weird hey???

Once I did some investigation I noticed CRM trying to call a domain controller which was no more, so I found this registry hkey:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\MSCRM

You will notice a key called: PreferredDc

If you set this key ensure it points to a valid domain controller, in our case this pointed to a domain controller which was no longer a domain controller

If you do not have this key then CRM will auto discover the domain controller.