#!/bin/bash #define variables laptop="ML-" workstation="MW-" server="S-" tld="encom.com" adusername="svcadmin" adpass="flynnlives!" # grabbing mac serial number... serial=$(ioreg -l |grep "IOPlatformSerialNumber"|cut -d ""="" -f 2|sed -e s/[^[:alnum:]]//g) # and model name... model=$(ioreg -l |grep "product-name" |cut -d ""="" -f 2|sed -e s/[^[:alnum:]]//g | sed s/[0-9]//g) # renaming based on model ie. prefix-computerserial.tld case"$model"in "MacBookPro" ) /usr/sbin/scutil --set ComputerName "$laptop$serial" /usr/sbin/scutil --set LocalHostName "$laptop$serial" /usr/sbin/scutil --set HostName "${laptop}${serial}.${tld}" echo"$model" echo"$laptop$serial" echo"${laptop}${serial}.${tld}" ;; "MacBookAir" ) /usr/sbin/scutil --set ComputerName "$laptop$serial" /usr/sbin/scutil --set LocalHostName "$laptop$serial" /usr/sbin/scutil --set HostName "${laptop}${serial}.${tld}" echo"$model" echo"$laptop$serial" echo"${laptop}${serial}.${tld}" ;; "MacPro" ) /usr/sbin/scutil --set ComputerName "$workstation$serial" /usr/sbin/scutil --set LocalHostName "$workstation$serial" /usr/sbin/scutil --set HostName "${workstation}${serial}.${tld}" echo"$model" echo"$workstation$serial" echo"${workstation}${serial}.${tld}" ;; "iMac" ) /usr/sbin/scutil --set ComputerName "$workstation$serial" /usr/sbin/scutil --set LocalHostName "$workstation$serial" /usr/sbin/scutil --set HostName "${workstation}${serial}.${tld}" echo"$model" echo"$workstation$serial" echo"${workstation}${serial}.${tld}" ;; "Macmini" ) /usr/sbin/scutil --set ComputerName "$server$serial" /usr/sbin/scutil --set LocalHostName "$server$serial" /usr/sbin/scutil --set HostName "${server}${serial}.${tld}" echo"$model" echo"$server$serial" echo"${server}${serial}.${tld}" ;; * ) echo"Computer model not found." exit 0 ;; esac # Add computer to Active Directory echo"Adding computer to Active Directory" dsconfigad -domain -a $tld -u $adusername -p $adpass -ou "ou=utg-mac,ou=laptops,dc=utg,dc=uvn,dc=net" -u -mobile disable -mobileconfirm disable -groups "domain admins@encom.com, enterprise admins@encom.com" dscl /Search/Contacts -create / SearchPolicy CSPSearchPath dscl /Search/Contacts -append / CSPSearchPath "/Active Directory/All Domains"
Comments