Skip to main content
Question

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

  • May 28, 2019
  • 2 replies
  • 18 views

Forum|alt.badge.img+3

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

Forum|alt.badge.img+17
  • Valued Contributor
  • May 28, 2019

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


Forum|alt.badge.img+3
  • Author
  • New Contributor
  • May 28, 2019

Worked! Thanks!