/build/static/layout/Breadcrumb_cap_w.png

Script for renaming mac computers based on their models and adding them to domain

#!/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

This post is locked

Don't be a Stranger!

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

Sign up! or login

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