ARD Unix Command Help - Answer Yes? - Automate Domain Unjoin / Rejoin

ssnyderMT
New Contributor

We had a bunch of Macs come up with no network access this morning, and unjoining and rejoining the domain fixes that. I'm trying to make this as automated as possible.

The following works great from Terminal with "yes | sudo sh myscript.sh", but I'm not sure how to make the UNIX Command answer yes when prompted when it says "Computer account already exists! Bind to Existing? (y/n):"

Here's what I have, and any advice is appreciated:

domain="mydomain"

username="myusername" password="mypassword"

olddomain=$( dsconfigad -show | awk '/Active Directory Domain/{print $NF}' ) computername=$( scutil --get ComputerName ) adcomputerid=$( echo "${computername}" | tr [:lower:] [:upper:] ) prefix="${adcomputerid:0:6}"

dsconfigad -remove -force -u "${username}" -p "${password}"

dsconfigad -add "${domain}" -username "${username}" -password "${password}"

2 REPLIES 2

joshuasee
Contributor III

You don't need to say yes. dsconfigad has a switch, -force, that causes it to skip the question.

ssnyderMT
New Contributor

Worked! Thanks!