Domain Join >>>Suggestion

KarmaLama
New Contributor

We have 3 domains in our org , how do i automate the domain join based on Site codes.

For eg :: We have total 553 sites in total and based on site code, i need to automate the domain join. Like site code starting with xyz should bind to first domain. Similarly site code with abc should join to second domain.

Thanks in advance !!

1 REPLY 1

m_donovan
Contributor III

You could do it with a script that gets the site info using the API and pulls out the organization code. Using a case statement with a default domain run a policy based on org. code. This is rough and completely untested but it should give you the idea. As I used to hear in the Army this is "A" way not "The" way. Hope it helps.

#!/bin/bash

apiuser="username"
apipass="password"
jssurl-"https://your.jss.address:8443"

# Get the computer serial number
deviceSerial=$( ioreg -rd1 -c IOPlatformExpertDevice | awk -F'"' '/IOPlatformSerialNumber/{print $4}' )

# Get computer site info
computerSite=$(curl -H "Accept: text/xml" -sfku "${apiuser}:${apipass}" "${jssurl}/JSSResource/computers/serialnumber/${deviceSerial}" -X GET 2>/dev/null | xmllint --format - | grep -B1 "</site>" | awk -F'>|<' '/<name>/{print $3}')

# Pull the first 3 characters from the site info
orgCode=$(echo $computerSite | awk '{print substr($0,0,3)}')

# Based on the orgCode run a policy to bind to the domain
case $orgCode in 
    100) jamf policy -event bindto100 ;;
    200) jamf policy -event bindto200 ;; 
    300) jamf policy -event bindto300 ;;
    *) jamf policy -event bindtoDefault ;;
esac

exit 0