Created
January 8, 2012 23:29
-
-
Save acidprime/1580101 to your computer and use it in GitHub Desktop.
Open Directory to Active Directory LDIF export
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
IFS=$'\n' | |
LDAP_SERVER="localhost" | |
ldapsearch -LLL -h "$LDAP_SERVER" -x -D uid=diradmin,cn=users,dc=example,dc=com -w password -b cn=users,dc=example,dc=com '(&(objectClass=posixAccount)(!(uid=root))(!(uid=diradmin))(!(uid=vpn_*)))' \ | |
cn \ | |
sn \ | |
givenName \ | |
uidNumber \ | |
uid \ | |
l \ | |
st \ | |
postalCode \ | |
street \ | |
c \ | |
telephoneNumber \ | |
apple-imhandle \ | |
mail \ | |
mobile \ | |
apple-keyword \ | |
description | | |
sed 's/^dn: uid=/dn: cn=/g' | | |
sed 's@^$@userAccountControl: 66080\ | |
codePage: 0\ | |
accountExpires: 0\ | |
countryCode: 0\ | |
logonHours:: ////////////////////////////\ | |
@g' | | |
sed 's/^uid:/sAMAccountName:/g' | | |
sed 's/cn=users,dc=example,dc=com/ou=ImportedUsers,dc=ad,dc=example,dc=com\ | |
changetype: add\ | |
objectClass: top\ | |
objectClass: person\ | |
objectClass: organizationalPerson\ | |
objectClass: user\ | |
objectClass: apple-user\ | |
instanceType: 4\ | |
objectCategory: cn=Person,cn=Schema,cn=Configuration,dc=ad,dc=example,dc=com/g' | | |
while read line ; do | |
if [ "$line" != "${line/dn://}" ] ; then | |
declare MY_UID="$(echo "$line" | awk -F '[=,]' '/^dn:/{print $2}' )" | |
declare MY_CN="$(ldapsearch -LLL -h "$LDAP_SERVER" -x -D uid=diradmin,cn=users,dc=example,dc=com -w password -b cn=users,dc=example,dc=com "(&(objectClass=posixAccount)(&(uid=$MY_UID)))" cn | | |
awk /^cn:/ | | |
sed 's/^cn: //g')" | |
declare MY_NEWLINE="$(echo "$line" | sed "s/$MY_UID/$MY_CN/" )" | |
echo "$MY_NEWLINE" | |
else | |
echo "$line" | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment