Note: machine names already exist in AD.
 
#!/bin/bash

### You must edit these for your specific ROOM

# 1) fully qualified DNS name of Active Directory Domain.

domain="acme.tools.com"

# 2) username of a privileged network user.

udn="macjoiner"

# 3) password of a privileged network user.

password=XXXXXX

# 4) Distinguished name of container for the computer

ou="cn=Room-100,ou=MACs,ou=mainsite,dc=acme,dc=tools,dc=com"

# 5) 'enable' or 'disable' automatic multi-domain authentication

alldomains="disable"

### End of configuration

# Get the local computer's name.

computerid=`/usr/sbin/scutil --get LocalHostName`

# Activate the AD plugin, just to be sure

defaults write /Library/Preferences/DirectoryService/DirectoryService "Active Directory" "Active" plutil -convert xml1 /Library/Preferences/DirectoryService/DirectoryService.plist

# Bind to AD

dsconfigad -f -a $computerid -domain $domain -u "$udn" -p "$password" -ou "$ou"

dsconfigad -alldomains $alldomains

# Add the AD node to the search path

if [ "$alldomains" = "enable" ]; then

csp="/Active Directory/All Domains"

else

csp="/Active Directory/$domain"

fi

dscl /Search -append / CSPSearchPath "$csp"

dscl /Search -create / SearchPolicy dsAttrTypeStandard:CSPSearchPath

dscl /Search/Contacts -append / CSPSearchPath "$csp"

dscl /Search/Contacts -create / SearchPolicy dsAttrTypeStandard:CSPSearchPath

# Restart Directory Service

killall DirectoryService

sleep 2

exit 0