ARD Unix Command Help - Answer Yes? - Automate Domain Unjoin / Rejoin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Posted on 05-28-2019 10:51 AM
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}"

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Posted on 05-28-2019 10:54 AM
You don't need to say yes. dsconfigad has a switch, -force, that causes it to skip the question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Posted on 05-28-2019 01:04 PM
Worked! Thanks!
