forked from boberito/jamfscripts
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDEP Rename-Post.sh
67 lines (53 loc) · 2.25 KB
/
DEP Rename-Post.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/bin/sh
#On Enrollment run the script from
#https://www.macblog.org/post/automatically-renaming-computers-from-a-google-sheet-with-jamf-pro/
#Computer is renamed, now at first login it'll personalize that
#Runs at login to set computer name, re-joins AD, and sets user and department
InventoryTag=$(hostname)
LoggedInUser=$(ls -l /dev/console | awk '{ print $3 }')
echo "Hello $LoggedInUser on $InventoryTag"
#Checks if a faculty or staff...if not it's a student.
if dscl '/Active Directory/ACADEMIC/All Domains' -read /Users/"$LoggedInUser" | grep "Faculty and Staff"; then
ComputerName=$InventoryTag$(echo $LoggedInUser | cut -c 2-)
echo "Employee"
#pops up pashua to set user and department
jamf policy -event setdeptDEP
touch /var/.faculty
if [ -e "/var/.student" ]; then
rm /var/.student
echo "no longer student"
fi
else
echo "Student"
ComputerName="S"$InventoryTag
#gets user info from AD to populate
getclass=`dscl '/Active Directory/ACADEMIC/All Domains' -read /Users/$LoggedInUser dsAttrTypeNative:distinguishedName | awk '{ FS=","; print $2 }' | awk '{ FS="="; print $2 }' | tail -1`
getRealName=$(id -F "$LoggedInUser")
#getRealName=`dscl '/Active Directory/ACADEMIC/All Domains' -read /Users/$LoggedInUser RealName | grep -v ":"`
if [ -e "/var/.staff" ]; then
rm /var/.staff
echo "no longer staff"
fi
if [ -e "/var/.faculty" ]; then
rm /var/.faculty
echo "no longer faculty"
fi
touch /var/.student
echo "My Class is - $getclass"
echo "My Full Name is - $getRealName"
jamf recon -endUsername $LoggedInUser -department "$getclass" -building "Postoak" -realname "$getRealName" -email "[email protected]" &
fi
echo "My Computer's new name is $ComputerName"
echo $ComputerName > /var/.computername
#removes from AD, renames computer, and rejoins AD
#does an authenticated AD remove which removes it from AD server itself
dsconfigad -remove -u ENTER-AD-USER -p ENTER-AD-PASSWORD
scutil --set ComputerName "$ComputerName"
scutil --set LocalHostName "$ComputerName"
scutil --set HostName "$ComputerName"
jamf setComputerName -name "$ComputerName"
dscacheutil -flushcache
#Rejoin AD
jamf policy -event joinad
rm -f /var/tmp/computernames.csv
exit 0