Here is a script we are using as a post-installation task to enable SSH, set the computer name, and then join the computer to our Active Directory managed domain. 

Note: the template we are using to name our Macs is the letter 'M' followed by the serial number. You can edit the script to take out the M before "$SN", or you can append anything else you'd like onto it, such as an asset take or location. 

Please set HOST, DOMAIN, ADUSERNAME, and ADPASS to match the information for your domain. ADUSERNAME and ADPASS should be a user with sufficient privilages to add the computers to the domain. 

#!/bin/bash 

HOST="ADserver.domain.com"

DOMAIN="domain.com"

ADUSERNAME="admin"

ADPASS="secretpassword"

 

# Enable SSH

echo "Enabling SSH"

systemsetup -setremotelogin on

launchctl load -w /System/Library/LaunchDaemons/ssh.plist

 

# Find the serial number

SN=$(system_profiler | grep 'r (system)' | tail -1 | awk '{print $4}')

echo "Serial Number: $SN"

 

# Set HostName, LocalHostName, and ComputerName to M$SN

echo "Setting computer names to M$SN"

scutil --set HostName M$SN

scutil --set LocalHostName M$SN

scutil --set ComputerName M$SN

 

# Add computer to Active Directory

echo "Adding computer to Active Directory"

dsconfigad -preferred $HOST -domain $DOMAIN -u $ADUSERNAME -p $ADPASS