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
 

 

Answer Summary:
Cancel
0 Comments   [ + ] Show Comments

Comments

Please log in to comment

Answers

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

Answered 06/10/2013 by: SMal.tmcc
Red Belt

  • 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
    • 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"
  • Thx. Will try That
Please log in to comment
Answer this question or Comment on this question for clarity