-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsetComputerName.sh
More file actions
28 lines (19 loc) · 1013 Bytes
/
setComputerName.sh
File metadata and controls
28 lines (19 loc) · 1013 Bytes
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
#!/bin/sh
# Checking jamf location
jamf=$(which jamf)
# Get mac serial number
serialNumber=$( ioreg -c IOPlatformExpertDevice -d 2 | awk -F\" '/IOPlatformSerialNumber/{print $(NF-1)}' )
# Getting the logged-in user
loggedInUser=$(python -c 'from SystemConfiguration import SCDynamicStoreCopyConsoleUser; import sys; username = (SCDynamicStoreCopyConsoleUser(None, None, None) or [None])[0]; username = [username,""][username in [u"loginwindow", None, u""]]; sys.stdout.write(username + "\n");')
# Formatting computer name
computerName=$loggedInUser'-mac-'$serialNumber
# 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