When deploying an operating system, automating the domain join process is pretty straightforward. There is a task sequence step called Recover from Domain that runs a script called ZTIDomainJoin.WSF. This script automates the whole process. It uses variables that can be set in a task sequence or in the customsettings.ini like in this example:
JoinDomain=scriptimus.local DomainAdmin=ScriptimusPrime DomainAdminDomain=scriptimus.local DomainAdminPassword=H4rdP4$$0rd
If you upgrade or replace a machine it will use the same computername and stay in the same OU where the current computer account exists. For new machines you can specify the Organization to which you new machine will be placed. For example:
When creating reference images I dont usually join the domain unless I have to. In those cases I use an isolated OU as above.
In other instances to join a custom workgroup you can use these settings: