Here is a handy batch file that will check if a Windows machine has already joined a domain, and if it has not, it will join and reboot.
This is useful for automated server deployments where the script will ensure the machine joins the domain at first boot. I have recently used it in Azure Batch as a startup task to ensure pool machines join the domain.
1 2 3 4 5 6 7 8 9 10 11 12 |
echo "Searching For Domain Status" for /f "tokens=2" %%i in ('systeminfo ^| find "Domain"') do (set "DOMAIN=%%i") if "%DOMAIN%" == "WORKGROUP" ( echo "Joining Domain" netdom join /d:mydomain.com %COMPUTERNAME% /ud:[USER] /pd:[PASSWORD] echo "Rebooting" shutdown.exe /r /t 00 ) else ( echo "Already in Domain" ) |