-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathset_computername-sn.sh
More file actions
48 lines (40 loc) · 1.59 KB
/
set_computername-sn.sh
File metadata and controls
48 lines (40 loc) · 1.59 KB
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
#!/bin/bash
###
#
# Name: set_computername-sn.sh
# Description: This script is designed to set a computer name during automated enrollment as follows:
# 1- Get serial name
# 2- Format the computer name
# 3- Set computer name/hostname/local hostname and NetBIOSName using formatted name
# 4- To be overly thorough, use jamf setcomputername to set name as well
#
###
# Checking jamf location
jamf=$(which jamf)
# Getting the logged-in user
serialNumber=$( /usr/sbin/system_profiler SPHardwareDataType | awk '/Serial/ {print $4}' )
# Get Model Name
modelName=$( /usr/sbin/system_profiler SPHardwareDataType | grep "Model Name" | awk '{print $3,$4}' )
if [[ "$modelName" == *"MacBook Air"* ]]; then
computerName="${serialNumber}MBA"
elif [[ "$modelName" == *"MacBook Pro"* ]]; then
computerName="${serialNumber}MBP"
elif [[ "$modelName" == *"Mac mini"* ]]; then
computerName="${serialNumber}MM"
elif [[ "$modelName" == *"iMac"* ]]; then
computerName="${serialNumber}IM"
elif [[ "$modelName" == *"Mac Studio"* ]]; then
computerName="${serialNumber}MS"
else
computerName="${serialNumber}MAC"
fi
# Setting computername
echo "Setting computer name to $computerName locally..."
scutil --set ComputerName "$computerName"
scutil --set HostName "$computerName"
scutil --set LocalHostName "$computerName"
defaults write /Library/Preferences/SystemConfiguration/com.apple.smb.server NetBIOSName "$computerName"
# Sending computername to Jamf
"$jamf" setcomputername -name "$computerName"
echo "Computer name set to $computerName!"
exit 0