unbindAD.sh (change DirectoryService to opendirectoryd for Lion and later)

donmontalvo
Esteemed Contributor III

FYI...the process name changed as of Lion (was DirectoryService, but is now opendirectoryd):

https://jamfnation.jamfsoftware.com/viewProductFile.html?id=135&fid=438

PS, sending email to our rep.

Thanks,
Don

--
https://donmontalvo.com
1 ACCEPTED SOLUTION

donmontalvo
Esteemed Contributor III

I just made a couple changes and saved it as unbindAD107.sh.

I added a processname variable, and I used the long options as per 10.7/10.8 man page (-username instead of -u).

Changes are in bold, I edited out the top half of the script for brevity (since it's all comments):

###########################################################################
#
# DEFINE VARIABLES & READ IN PARAMETERS
#
###########################################################################


# HARDCODED VALUES ARE SET HERE
username=""
password=""
**processname="opendirectoryd"**

# CHECK TO SEE IF A VALUE WAS PASSED IN PARAMETER 4 AND, IF SO, ASSIGN TO "username"
if [ "$4" != "" ] && [ "$username" == "" ]; then
    username=$4
fi

# CHECK TO SEE IF A VALUE WAS PASSED IN PARAMETER 5 AND, IF SO, ASSIGN TO "password"
if [ "$5" != "" ] && [ "$password" == "" ]; then
    password=$5
fi

###########################################################################
#
# SCRIPT CONTENTS - DO NOT MODIFY BELOW THIS LINE
#
###########################################################################
if [ "$username" == "" ]; then
    echo "Error:  No username is specified.  Please specify a network username."
    exit 1
fi

if [ "$password" == "" ]; then
    echo "Error:  No password is specified.  Please specify a network password."
    exit 1
fi


echo "Unbinding the computer from Active Directory..."
/usr/sbin/dsconfigad **-remove -username** $username **-password** $password

echo "Restarting Directory Services..."
/usr/bin/killall **$processname**
--
https://donmontalvo.com

View solution in original post

1 REPLY 1

donmontalvo
Esteemed Contributor III

I just made a couple changes and saved it as unbindAD107.sh.

I added a processname variable, and I used the long options as per 10.7/10.8 man page (-username instead of -u).

Changes are in bold, I edited out the top half of the script for brevity (since it's all comments):

###########################################################################
#
# DEFINE VARIABLES & READ IN PARAMETERS
#
###########################################################################


# HARDCODED VALUES ARE SET HERE
username=""
password=""
**processname="opendirectoryd"**

# CHECK TO SEE IF A VALUE WAS PASSED IN PARAMETER 4 AND, IF SO, ASSIGN TO "username"
if [ "$4" != "" ] && [ "$username" == "" ]; then
    username=$4
fi

# CHECK TO SEE IF A VALUE WAS PASSED IN PARAMETER 5 AND, IF SO, ASSIGN TO "password"
if [ "$5" != "" ] && [ "$password" == "" ]; then
    password=$5
fi

###########################################################################
#
# SCRIPT CONTENTS - DO NOT MODIFY BELOW THIS LINE
#
###########################################################################
if [ "$username" == "" ]; then
    echo "Error:  No username is specified.  Please specify a network username."
    exit 1
fi

if [ "$password" == "" ]; then
    echo "Error:  No password is specified.  Please specify a network password."
    exit 1
fi


echo "Unbinding the computer from Active Directory..."
/usr/sbin/dsconfigad **-remove -username** $username **-password** $password

echo "Restarting Directory Services..."
/usr/bin/killall **$processname**
--
https://donmontalvo.com