Demote server 2012 R2 with Powershell

uninstall-adddomaincontroller -lastdomaincontrollerindomain -removeapplicationpartitions

This will still fail if you have the box ticked in AD that protects the object from deletion.