Skip to main content

We are facing issue with the computer name when we are trying to enroll it to our jss. what we did is we reimage all our harddrive using imaging tool and name the computer name as "UAS", and now when we are trying to change it to other computer name it will change but after restarting the macbook it will go back again to "UAS" or "UAS (2)" but on the jss it did not change, only on the computer name of the macbook.

You have to change the name in 3 different places on the computer in order for it to stick. Below is the 3 commands we use to change computer names.



scutil --set HostName $COMPUTERNAME
scutil --set LocalHostName $COMPUTERNAME
scutil --set ComputerName $COMPUTERNAME


Here's the script we run. We set the workstation name by the serial number. This will check for new machines ("Macintosh HD") or machines that got wiped and not renamed by disk utility ("Untitled 1"). Also, and I am sure someone else on here can elaborate why, but 10.10 (I think it was) started setting the boot disk as disk0 vs disk1. It also sets the hard drive name to the serial number for easier identification.



#!/bin/bash

serial=`/usr/sbin/system_profiler SPHardwareDataType | /usr/bin/awk '/Serial Number (system)/ {print $NF}'`
/usr/sbin/scutil --set ComputerName "${base}${serial}"
/usr/sbin/scutil --set LocalHostName "${base}${serial}"
/usr/sbin/scutil --set HostName "${base}${serial}"

HDDName=`/usr/sbin/diskutil list | grep "Macintosh HD" | grep disk0`
HDDCSName=`/usr/sbin/diskutil list | grep "Macintosh HD" | grep disk1`
UntName=`/usr/sbin/diskutil list | grep "Untitled 1" | grep disk0`
Unt2Name=`/usr/sbin/diskutil list | grep "Untitled 1" | grep disk1`


if [ "$HDDName" != "" ]; then
diskutil rename disk0s2 "${base}${serial}"
elif [ "$HDDCSName" != "" ]; then
diskutil rename disk1 "${base}${serial}"
elif [ "$UntName" != "" ]; then
diskutil rename disk0s2 "${base}${serial}"
elif [ "$Unt2Name" != "" ]; then
diskutil rename disk1 "${base}${serial}"
fi

@jamfmdm the reason you are seeing the name not change in the JSS is because you are most likely not doing a recon after changing the computer name. Using one of the methods that others have posted (utilizing scutil), the last step is to recon the computer with jamf recon. If you do not do this, the JSS will not know of the name change until the next scheduled recon.


@chet.bishop i will run that command on terminal right? before or after enrolling the macbook we need to run that command?


@stevewood after changing the computer name we should run jamf recon to the computer that we made change?


@jamfmdm What I do is enroll the workstation via a Quick Add package, and set the rename script as self service policy along with a few other-post image actions (AD Bind, etc). And once that's done, I run a recon then. You can push this script via Casper Remote with a checked-box on Update Inventory and it will catch the name change then, too. You could also add a



jamf recon


at the end of the script, which will do it every time. I find that unnecessary/overkill because I'm usually doing other things that will require a recon as well, so I try to keep that action at a minimum to save time.



BTW - why are you naming each computer with the same name? Isn't that a confusing workflow?


@jamfmdm yes, after you have changed the name on the computer, you need to run jamf recon on the computer to change the name in the JSS.


@stevewood but after enrolling the computer i could not change the computer name anymore. its grayed out. is there any command i could force the computer name on the jss going to the computer?


@easyedc i'm not naming them as same. what i'm doing i reimage all our harddrive from a fresh yosemite os then we are changing the computer name as per user name. then after the enrollment it will change again to the default computer name.


How are you imaging? If you're using Casper Imaging, it can write the name for you based on a few variables.


@jamfmdm here is the full script we use and then we just created a policy within self service to run. Otherwise you can run those commands individually to change them in terminal. Scripting it is much easier though :)



#!/bin/sh

# Set CocoaDialog Location
###CD="/Path/to/CocoaDialog.app/Contents/MacOS/CocoaDialog"
CD_APP="/private/var/ahc-umn/bin/CocoaDialog.app"
CD="$CD_APP/Contents/MacOS/CocoaDialog"

# Dialog to enter the computer name and the create $COMPUTERNAME variable
rv=($($CD standard-inputbox --title "Computer Name" --no-newline --informative-text "Enter the computer name you wish to set"))
COMPUTERNAME=${rv[1]}

# Set Hostname using variable created above
scutil --set HostName $COMPUTERNAME
scutil --set LocalHostName $COMPUTERNAME
scutil --set ComputerName $COMPUTERNAME

# Dialog to confirm that the hostname was changed and what it was changed to.
tb=`$CD ok-msgbox --text "Computer Name Changed!"
--informative-text "The computer name has been changed to $COMPUTERNAME"
--no-newline --float`
if [ "$tb" == "1" ]; then
echo "User said OK"
elif [ "$tb" == "2" ]; then
echo "Canceling"
exit
fi

I use ARD to change the name of the machine. Send a unix command just make sure you are sending it as root.



sudo scutil --set LocalHostName "NEW NAME HERE"
sudo scutil --set HostName "NEW NAME HERE"
sudo scutil --set ComputerName "NEW NAME HERE"
sudo scutil --get LocalHostName
sudo scutil --get HostName
sudo scutil --get ComputerName
killAll cfprefsd


@jamfmdm as @chet.bishop posted above, you can use a script as part of a Self Service policy to change the name. His script uses cocoaDialog to ask the user what name you want the computer to be, renames the computer, and then displays the new computer name, again using cocoaDialog. The only thing I would say about this method is to either place jamf recon at the end of the script (perhaps before displaying the name) or make sure that the policy has "Update Inventory" selected on the Maintenance tab of the policy:





You can also simply open Terminal and then issue the following commands, filling in <computername> with the name you want the computer to be:



sudo scutil --set ComputerName <computername>
sudo scutil --set HostName <computername>
sudo scutil --set LocalHostName <computername>
jamf recon


That will rename the computer and then recon the computer, which will change the name in the JSS.



To answer your last question to me, whether you can force the name change from the JSS, the answer is yes. If you set the name in the JSS, you can update your inventory update policy (mine is "Update Inventory") or create a new policy to update inventory, and on the Maintenance tab choose "Update Inventory" and "Reset Computer Names". You can see that I have both of those checked in my Update Inventory policy that I posted above.



Hope that helps.


@chet.bishop @stevewood i will enable it to our selfservice what should i put for the policy trigger?


@chet.bishop the script you made will ask the user what computer name they want to put? but when i tried to use it using self service there is an error. do i need to put any parameter?


is there any way or script that will make the the computer name as the username in the inventory of our jss?


@jamfmdm You could do that using the API... But why based on Username?



Typically we set names to the Macs SerialNumber... & the JAMF binary can do this easily.



This has the benefit of being the same name that's on the device as well as (by coincidence), falling in with AD's character limitiations for Computer Objects.



Then, if you want to track who's Mac is who's.. You can search for the username in the JSS.


@bentoms it is more easier on our part who owns or use the laptop. and it is more easier to push some application that teacher need to be installed.


This is the error message that we are getting if the computer will change automatically.
that will just pop out

the computer name will just change


@chet.bishop hi. i'm trying the script that you gave me but still not working.i even tried to find the cocoadialog location but it's not showing to me. i think your script is good for our environment if that will work.


@jamfmdm We install cocoadialog on all of our machines. Do you have the cocoadialog app installed on your devices? If not, I believe you can download it from github and install the package.



Are you receiving an error at a certain part?


@chet.bishop it's working now. thanks! but are still facing issue with changing name automatically. but the that you gave is good to our environment. :)


I tried running the script posted by easyedc within a policy and I get this message:



Executing Policy Computer Name Change
Running script Computer Name Change...
Script exit code: 1
Script result: Volume must be mounted



What do I need to do to resolve this?



thanks


I used to run a disk renaming script at my last gig, I think it's a bit more straightforward, no need to try to test for which disk it thinks it is:



#!/bin/sh

export VolumeName=`diskutil info / | grep "Volume Name" | cut -c 30-`

if [ "$VolumeName" != "Macintosh HD" ];
then diskutil renameVolume "$VolumeName" "Macintosh HD"
fi

Long live Apple Script!



#!/usr/bin/osascript
-- script to change computer name so it is NOT new users macbook pro
-- Ask for new computer name

set COMPUTERNAME to text returned of (display dialog "Please enter new Computer Name:" default answer "unameXXmbpXX" with icon 2)
display dialog "New Computer name will be: " & COMPUTERNAME
--
# Set Hostname, LoacalHostName, and ComputerName using variable created above
do shell script "scutil --set HostName " & COMPUTERNAME
do shell script "scutil --set LocalHostName " & COMPUTERNAME
do shell script "scutil --set ComputerName " & COMPUTERNAME
--
--get new names and set as new variable
--
set newHostName to do shell script "scutil --get HostName"
set newLocalHostName to do shell script "scutil --get LocalHostName"
set newComputerName to do shell script "scutil --get ComputerName"
--
-- Display dialog to confirm computer names were changed.
display dialog "The computer Host Name has been changed to: " & newHostName & "

The computer Local Host Name has been changed to: " & newLocalHostName & "

The computer Name has been changed to: " & newComputerName buttons {"Roger That"} default button "Roger That" with icon 2

Reply