/build/static/layout/Breadcrumb_cap_w.png

Join Active Directory Domain

This Script works for me but how do i change 2 things

 

1 I want the computers not to be in Container Computers but in Organizational Unit named "MMac"

 

2 I want the computername to be somthing like MMAC$$$

Where $$$ a Unique number out of Mac adress.

How do i getabout those 2 things

 

 

 

 

#!/bin/bash 

 

HOST="FQDN Domain Controler"

 

DOMAIN="FQDN"

 

ADUSERNAME="sa_inspoel"

 

ADPASS="Password"

 

 

 

# Enable SSH

 

echo "Enabling SSH"

 

systemsetup -setremotelogin on

 

launchctl load -w /System/Library/LaunchDaemons/ssh.plist

 

 

 

# Find the serial number

 

SN=$(system_profiler | grep 'r (system)' | tail -1 | awk '{print $4}')

 

echo "Serial Number: $SN"

 

 

 

# Set HostName, LocalHostName, and ComputerName to M$SN

 

echo "Setting computer names to M$SN"

 

scutil --set HostName M$SN

 

scutil --set LocalHostName M$SN

 

scutil --set ComputerName M$SN

 

 

 

# Add computer to Active Directory

 

echo "Adding computer to Active Directory"

 

dsconfigad -preferred $HOST -domain $DOMAIN -u $ADUSERNAME -p $ADPASS

 

 

 

Or can I use This Script

 

 

And what do i need to Edit to make this work

 

 

 

#!/bin/bash

 

### You must edit these for your specific environment

 

# 1) fully qualified DNS name of Active Directory Domain. 

domain="network.local"

 

# 2) username of a privileged network user.

udn="USERNAME"

 

# 3) password of a privileged network user.

password="PASSWORD"

 

# 4) Distinguished name of container for the computer

ou="ou=Computers,DC=network,DC=local"

 

# 5) 'enable' or 'disable' automatic multi-domain authentication

alldomains="enable"

 

### End of configuration

 

# Get the local computer's name.

computerid=`/usr/sbin/scutil --get LocalHostName`

 

# Activate the AD plugin, just to be sure

defaults write /Library/Preferences/DirectoryService/DirectoryService "Active Directory" "Active"

plutil -convert xml1 /Library/Preferences/DirectoryService/DirectoryService.plist

 

# Bind to AD

VERSION=`/usr/libexec/PlistBuddy -c "Print :ProductVersion" "/System/Library/CoreServices/SystemVersion.plist"`

case "$VERSION" in

    10.[5-6]*)

       dsconfigad -f -a $computerid -domain $domain -u "$udn" -p "$password" -ou "$ou"

        ;;

    10.[7-8]*)

        dsconfigad -force -add $domain -computer $computerid  -username "$udn" -password "$password" -ou "$ou"

        ;;

    *)

        echo "Unsupported version of OS"

        ;;

esac

 

dsconfigad -alldomains $alldomains

 

# Add the AD node to the search path

if [ "$alldomains" = "enable" ]; then

csp="/Active Directory/All Domains"

else

csp="/Active Directory/$domain"

fi

 

dscl /Search -append / CSPSearchPath "$csp"

dscl /Search -create / SearchPolicy dsAttrTypeStandard:CSPSearchPath

dscl /Search/Contacts -append / CSPSearchPath "$csp"

dscl /Search/Contacts -create / SearchPolicy dsAttrTypeStandard:CSPSearchPath

 

# Restart Directory Service

killall DirectoryService

sleep 2

 

exit 0
 

 


0 Comments   [ + ] Show comments

Answers (1)

Answer Summary:
Posted by: SMal.tmcc 11 years ago
Red Belt
0

not sure on naming but this is the script we use to join classroom machines to certain ou's

#!/bin/bash

### You must edit these for your specific CLASSROOM

# 1) fully qualified DNS name of Active Directory Domain.
domain="tmccacad.tmcc.edu"


# 2) username of a privileged network user.
udn="macjoiner"

# 3) password of a privileged network user.
password="xoxoxoxo"

# 4) Distinguished name of container for the computer
ou="cn=ATC-217,ou=MACs,ou=dandini,ou=campuses,dc=tmccacad,dc=tmcc,dc=edu"

# 5) 'enable' or 'disable' automatic multi-domain authentication
alldomains="disable"

### End of configuration

# Get the local computer's name.
computerid=`/usr/sbin/scutil --get LocalHostName`

# Activate the AD plugin, just to be sure
defaults write /Library/Preferences/DirectoryService/DirectoryService "Active Directory" "Active"
plutil -convert xml1 /Library/Preferences/DirectoryService/DirectoryService.plist

# Bind to AD
dsconfigad -f -a $computerid -domain $domain -u "$udn" -p "$password" -ou "$ou"
dsconfigad -alldomains $alldomains

# Add the AD node to the search path
if [ "$alldomains" = "enable" ]; then
    csp="/Active Directory/All Domains"
else
    csp="/Active Directory/$domain"
fi

dscl /Search -append / CSPSearchPath "$csp"
dscl /Search -create / SearchPolicy dsAttrTypeStandard:CSPSearchPath
dscl /Search/Contacts -append / CSPSearchPath "$csp"
dscl /Search/Contacts -create / SearchPolicy dsAttrTypeStandard:CSPSearchPath

# Restart Directory Service
killall DirectoryService
sleep 2

exit 0


Comments:
  • I edited Your script to

    Hope it will work. test it tomorrow



    #!/bin/bash

    ### You must edit these for your specific CLASSROOM

    # 1) fully qualified DNS name of Active Directory Domain.
    domain="network.local"


    # 2) username of a privileged network user.
    udn="sa_inspoel"

    # 3) password of a privileged network user.
    password="PASSWORD"

    # 4) Distinguished name of container for the computer
    # Computers will be placed in Imac Then Sub OU MLion

    ou="cn=ATC-217,ou=IMAC,ou=MLion,dc=network,dc=,dc=local"

    # 5) 'enable' or 'disable' automatic multi-domain authentication
    alldomains="enable"

    ### End of configuration

    # Get the local computer's name.
    computerid=`/usr/sbin/scutil --get LocalHostName`

    # Activate the AD plugin, just to be sure
    defaults write /Library/Preferences/DirectoryService/DirectoryService "Active Directory" "Active"
    plutil -convert xml1 /Library/Preferences/DirectoryService/DirectoryService.plist

    # Bind to AD
    dsconfigad -f -a $computerid -domain $domain -u "$udn" -p "$password" -ou "$ou"
    dsconfigad -alldomains $alldomains

    # Add the AD node to the search path
    if [ "$alldomains" = "enable" ]; then
    csp="/Active Directory/All Domains"
    else
    csp="/Active Directory/$domain"
    fi

    dscl /Search -append / CSPSearchPath "$csp"
    dscl /Search -create / SearchPolicy dsAttrTypeStandard:CSPSearchPath
    dscl /Search/Contacts -append / CSPSearchPath "$csp"
    dscl /Search/Contacts -create / SearchPolicy dsAttrTypeStandard:CSPSearchPath

    # Restart Directory Service
    killall DirectoryService
    sleep 2

    exit 0


    Am also gona test this version see if it works


    #!/bin/bash

    HOST="dct003.network.local"
    DOMAIN="network.local"
    ADUSERNAME="sa_inspoel"
    ADPASS="PASSWORD"

    # Enable SSH
    echo "Enabling SSH"
    systemsetup -setremotelogin on
    launchctl load -w /System/Library/LaunchDaemons/ssh.plist

    #'enable' or 'disable' automatic multi-domain authentication
    alldomains="enable"

    # Activate the AD plugin, just to be sure
    defaults write /Library/Preferences/DirectoryService/DirectoryService "Active Directory" "Active"
    plutil -convert xml1 /Library/Preferences/DirectoryService/DirectoryService.plist


    # Find the serial number
    SN=$(system_profiler | grep 'r (system)' | tail -1 | awk '{print $4}')
    echo "Serial Number: $SN"

    # Set HostName, LocalHostName, and ComputerName to M$SN
    echo "Setting computer names to M$SN"
    scutil --set HostName M$SN
    scutil --set LocalHostName M$SN
    scutil --set ComputerName M$SN

    # Add computer to Active Directory
    echo "Adding computer to Active Directory"
    dsconfigad -preferred $HOST -domain $DOMAIN -u $ADUSERNAME -p $ADPASS

    # Add the AD node to the search path
    if [ "$alldomains" = "enable" ]; then
    csp="/Active Directory/All Domains"
    else
    csp="/Active Directory/$domain"
    fi

    dscl /Search -append / CSPSearchPath "$csp"
    dscl /Search -create / SearchPolicy dsAttrTypeStandard:CSPSearchPath
    dscl /Search/Contacts -append / CSPSearchPath "$csp"
    dscl /Search/Contacts -create / SearchPolicy dsAttrTypeStandard:CSPSearchPath

    # Restart Directory Service
    killall DirectoryService
    sleep 2

    exit 0 - Raoul.tjin 11 years ago
    • you may want to fix this
      ou="cn=ATC-217,ou=IMAC,ou=MLion,dc=network,dc=,dc=local"
      the cn=atc-217 is the bottom container we want the machine to go in.
      you may want
      ou="cn=IMAC,ou=MLion,dc=network,dc=local" - SMal.tmcc 11 years ago
  • Thx. Will try That - Raoul.tjin 11 years ago

Don't be a Stranger!

Sign up today to participate, stay informed, earn points and establish a reputation for yourself!

Sign up! or login

View more:

Share

 
This website uses cookies. By continuing to use this site and/or clicking the "Accept" button you are providing consent Quest Software and its affiliates do NOT sell the Personal Data you provide to us either when you register on our websites or when you do business with us. For more information about our Privacy Policy and our data protection efforts, please visit GDPR-HQ