Home > Mac administration, Mac OS X Server, Scripting > Script to remove OD bindings

Script to remove OD bindings

At my workplace, I’m looking at retiring a 10.4 OD server which is bound to a number of Macs in my environment. To help automate the process, I’ve adapted a script which Patrick Gallagher was kind enough to share on his blog. It’s designed to check your Directory Service configuration, find if you’re bound to a specific OD server, and remove the bindings from your Mac. As always, use at your own risk and test, test, test. 🙂


#!/bin/sh

oldDomain="old.server.name" # Enter the FQDN of your old OD
oldODip="old.ip.here" # Enter the IP of your old OD

# These variables probably don't need to be changed
check4OD=`dscl localhost -list /LDAPv3`

# Check if bound to old Open Directory domain

if [ "${check4OD}" == "${oldDomain}" ]; then
echo "This machine is joined to ${oldDomain}"
echo "Removing from ${oldDomain}"
dsconfigldap -r "${oldDomain}"
dscl /Search -delete / CSPSearchPath /LDAPv3/"${oldDomain}"
dscl /Search/Contacts -delete / CSPSearchPath /LDAPv3/"${oldDomain}"
if [ "${odSearchPath}" = "" ]; then
echo "$oldDomain not found in search path."
fi

# Check if bound to old Open Directory domain's IP address

else if [ "${check4OD}" == "${oldODip}" ]; then
echo "This machine is joined to ${oldODip}"
echo "Removing from ${oldODip}"
dsconfigldap -r "${oldODip}"
dscl /Search -delete / CSPSearchPath /LDAPv3/"${oldODip}"
dscl /Search/Contacts -delete / CSPSearchPath /LDAPv3/"${oldODip}"
if [ "${odSearchPath}" = "" ]; then
echo "$oldODip not found in search path."
fi
fi
fi
killall DirectoryService
echo "Finished. Exiting..."
exit 0

Script with proper formatting

  1. alanft
    January 11, 2015 at 10:27 am

    I had to adapt this a bit. bound domains being case-insensitive, but the logic here being case-sensitive.

    provide oldDomain only in lowercase then you can use…

    check4ODlc=`echo ${check4OD} | tr ‘[[:upper:]]’ ‘[[:lower:]]’`

    if [ “${check4ODlc}” == “${oldDomain}” ]; then

    and instead of using ${oldDomain} in the subsequent operations use ${check4OD}

    dsconfigldap -r “${check4OD}”
    dscl /Search -delete / CSPSearchPath /LDAPv3/”${check4OD}”

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: