-
-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathRename Computer.sh
51 lines (41 loc) · 1.71 KB
/
Rename Computer.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
#!/bin/sh
####################################################################################################
#
# ABOUT
#
# Rename Computer
#
####################################################################################################
#
# HISTORY
#
# Version 1.0, 18-Jun-2015, Dan K. Snelson
# Original version
#
####################################################################################################
echo "*** Rename Computer ***"
### Log current computer name
currentComputerName=$( /usr/sbin/scutil --get ComputerName )
echo "Current Computer Name: $currentComputerName"
### Prompt for new computer name
newComputerName="$(/usr/bin/osascript -e 'Tell application "System Events" to display dialog "Enter the new computer name:" default answer "" buttons {"Rename","Cancel"} default button 2' -e 'text returned of result' 2>/dev/null)"
if [ $? -ne 0 ]; then
# The user pressed Cancel
echo "User clicked Cancel"
exit 1 # exit with an error status
elif [ -z "$newComputerName" ]; then
# The user left the computer name blank
echo "User left the computer name blank"
/usr/bin/osascript -e 'Tell application "System Events" to display alert "No computer name entered; cancelling." as critical'
exit 1 # exit with an error status
fi
### Set and log new computer name
/usr/sbin/scutil --set ComputerName "$newComputerName"
echo "New Computer Name: $newComputerName"
### Update the JSS
/usr/local/jamf/bin/jamf recon
# Inform user of computer renamed
/usr/local/jamf/bin/jamf displayMessage -message "Renamed computer from: \"$currentComputerName\" to \"$newComputerName\"" &
echo "Renamed computer from: \"$currentComputerName\" to \"$newComputerName\""
exit 0 ## Success
exit 1 ## Failure