echo "https://www.stefangordon.com/join-azure-batch-machines-active-directory/"
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:DOMAINNAME %COMPUTERNAME% /ud:USERNAME /pd:PASSWORD
 
 echo "Rebooting"
 shutdown.exe /r /t 00
) else (
 echo "Already in Domain"
)


echo "https://michlstechblog.info/blog/windows-join-a-workgroup-or-domain-from-command-line/"