Windows 7:

Install Package KB958830

cmd /c start /w pkgmgr /iu:RemoteServerAdministrationTools-Roles-AD-DS-SnapIns;RemoteServerAdministrationTools-Roles-AD-DS;RemoteServerAdministrationTools-Roles-AD;RemoteServerAdministrationTools-Roles;RemoteServerAdministrationTools

run batfile ==>

@echo off

hostname.exe > __t.tmp

set /p host=<__t.tmp

del __t.tmp

c:\windows\system32\netdom.exe remove /d:mydomain %host% /ud:mydomain\serviceaccount /pd:P@ssw0rd

Windows Server 2012 R2:

DISM /online /enable-feature /featurename=ActiveDirectory-Powershell /all

@echo off

hostname.exe > __t.tmp

set /p host=<__t.tmp

del __t.tmp

c:\windows\system32\netdom.exe remove /d:data %host%