Renaming a computer in Jamf does not get saved or applied to the computer hostname.

jnilsson
New Contributor

I'm looking to be able to rename a computer in Jamf Pro (in the web interface) and have it apply on the computer. I've seen others post more complex questions and use a script to rename multiple computers based on other info in the inventory, but we have external asset tags, so we're just gonna go in and manually name the computers using those tags (the tags are plain alphanumeric strings that come from our inventory asset system which get printed onto a barcode sticker that is placed on the computer, but we don't have a way to get that into Jamf).

It sounds like it should work to rename a computer using the instructions here:

https://learn.jamf.com/en-US/bundle/jamf-pro-documentation-current/page/Renaming_a_Computer.html

But I've tried several times, and after saving the name in Jamf Pro and waiting a day, the computer name on the macbook hasn't changed, and the name in Jamf Pro has reverted to the original computer name.

Does anyone know if this is expected to work? Are there minimum OS version requirements or anything else I'm missing? Is there a way to push the name change instead of just waiting a day to see what happens?

If you can't actually change the hostname of the computer from Jamf, I would still like to rename the computer within Jamf so that it matches our asset tag. But that doesn't seem to work either.

2 REPLIES 2

snowfox
Contributor III

Here are some ways, that I have previously used, to rename computers (but not in the way you want to do it.)

You can use the jamf binary to set the computer name and then run an inventory update which will update the name on the Computer Record within Jamf Pro.

 

 

#-------------------------------------------------------------------------------
# Dynamically set the computer name based on its hardware serial number + Prefix
#-------------------------------------------------------------------------------

jamf setComputerName -useSerialNumber -prefix MAC

# jamf recon   # (to update the machine name on Jamf Pro once it's set locally)  

 

 

 Type jamf help in Terminal for more details on available commands.

The other way is via a shell script.  This naming script can be run via a Policy on each computer to name computers (for example) in a computer lab with a specific naming convention.

 

 

#!/bin/sh

# Get the computer serial number (Hardware coded.  Doesn't require time to get up and running)
SERIALNUMBER=`system_profiler SPHardwareDataType | grep "Serial Number" | awk '{print $4}'`

#--------------------------------------------------------

# Allocate Name Value according to SERIAL NUMBER

# ----------------------------------------------------------------------------
# TEST MACHINES
# ----------------------------------------------------------------------------
if   [ "$SERIALNUMBER" = "XXXXXXXXXXXX" ]; then COMPUTERNAME="AA-AA12345-M01"
elif [ "$SERIALNUMBER" = "XXXXXXXXXXXX" ]; then COMPUTERNAME="AA-AA12345-M02"
elif [ "$SERIALNUMBER" = "XXXXXXXXXXXX" ]; then COMPUTERNAME="AA-AA12345-M03"


# ----------------------------------------------------------------------------
# COMPUTER LAB
# ----------------------------------------------------------------------------
elif [ "$SERIALNUMBER" = "XXXXXXXXXXXX" ]; then COMPUTERNAME="BB-BB12345-M01"
elif [ "$SERIALNUMBER" = "XXXXXXXXXXXX" ]; then COMPUTERNAME="BB-BB12345-M02"	
elif [ "$SERIALNUMBER" = "XXXXXXXXXXXX" ]; then COMPUTERNAME="BB-BB12345-M03"
elif [ "$SERIALNUMBER" = "XXXXXXXXXXXX" ]; then COMPUTERNAME="BB-BB12345-M04"
elif [ "$SERIALNUMBER" = "XXXXXXXXXXXX" ]; then COMPUTERNAME="BB-BB12345-M05"
elif [ "$SERIALNUMBER" = "XXXXXXXXXXXX" ]; then COMPUTERNAME="BB-BB12345-M06"
elif [ "$SERIALNUMBER" = "XXXXXXXXXXXX" ]; then COMPUTERNAME="BB-BB12345-M07"
elif [ "$SERIALNUMBER" = "XXXXXXXXXXXX" ]; then COMPUTERNAME="BB-BB12345-M08"
elif [ "$SERIALNUMBER" = "XXXXXXXXXXXX" ]; then COMPUTERNAME="BB-BB12345-M09"
elif [ "$SERIALNUMBER" = "XXXXXXXXXXXX" ]; then COMPUTERNAME="BB-BB12345-M10"


else COMPUTERNAME="UNKNOWN-SERIAL"	
fi

#--------------------------------------------------------

# Set computer name (as done via System Settings / General / Sharing)
scutil --set ComputerName "$COMPUTERNAME"
scutil --set HostName "$COMPUTERNAME"
scutil --set LocalHostName "$COMPUTERNAME"
defaults write /Library/Preferences/SystemConfiguration/com.apple.smb.server NetBIOSName -string "$COMPUTERNAME"

echo ""
echo "$COMPUTERNAME"
echo ""

#--------------------------------------------------------

# we don't want script to register as a failure in Jamf,  so always exit 0
exit 0

 

 

 This is what has worked for me in the past.  Set it first on the endpoint and then update the computer inventory via jamf recon to update the computer details on the Jamf Pro computer record automatically.

Forgot to mention, we are in a Windows / AD environment and there is a 15 character limit on hostnames if they are bound to legacy Active Directory.  If you don't have that then hostname length shouldn't be an issue for you.

Others may have a better way of doing this.

AJPinto
Esteemed Contributor

I dont think what you are wanting to do is possible, at least not the way you want it to. To set a computer name you need to do it with a script from Jamf using a policy. You can use jamf recon -assetTag | awk '{print $2}' to pull the asset tag from Jamf Pro and turn that in to a variable for the script to call when defining the hostname. 

 

This is not exactly naming the device by using the Jamf web console as that is not possible, but it is naming the device to match the asset tag and you can put this script in a policy to run as frequently as you like.

#!/usr/bin/bash
#*=============================================================================
#* Script Name: Hostname to Asset Tag
#* Created: [02/20/25]
#* Author:
#*=============================================================================
#* Purpose: Changes Mac hostname to match Jamf Pro Asset Tag if it does not already match
#*=============================================================================
 

#*=============================================================================
#* GLOBAL VARIABLES
#*=============================================================================
 
computerName=$(scutil --get ComputerName)
hostName=$(scutil --get HostName)
localHost=$(scutil --get LocalHostName)

# Get the Jamf Pro Asset Tag
assetTag=$(jamf recon -assetTag | awk '{print $2}')
 
#*=============================================================================
#* FUNCTIONS
#*=============================================================================
 

#*=============================================================================
#* SCRIPT BODY
#*=============================================================================
 
## Check & Update Computer Name
if [ "$computerName" == "$assetTag" ]
then
    echo "Computer name matches Jamf Pro Asset Tag, $assetTag"
else
    echo "Current Computer Name: $computerName"
    echo "Computer Name does not meet standards"
    echo "Changing Computer Name to match Jamf Pro Asset Tag"
    scutil --set ComputerName "$assetTag"  
fi; $DIV2
 
## Check & Update Host Name
if [ "$hostName" == "$assetTag" ]
then
    echo "Host Name matches Jamf Pro Asset Tag, $assetTag"
else
    echo "Current Host Name: $hostName"
    echo "Host Name does not meet standards"
    echo "Changing Host Name to match Jamf Pro Asset Tag"
    scutil --set HostName "$assetTag"
   
fi; $DIV2
 

## Check & Update Local Host
if [ "$localHost" == "$assetTag" ]
then
    echo "Local Host matches Jamf Pro Asset Tag, $assetTag"
else
    echo "Current Local Host: $localHost"
    echo "Local Host does not meet standards"
    echo "Changing Local Host to match Jamf Pro Asset Tag"
    scutil --set LocalHostName "$assetTag"
   
fi; $DIV2
 

## Final Check
computerNameII=$(scutil --get ComputerName)
hostNameII=$(scutil --get HostName)
localHostII=$(scutil --get LocalHostName)
 
echo "Results:"; $DIV3
echo "Jamf Pro Asset Tag: $assetTag"
echo "Computer Name: $computerNameII"
echo "Host Name: $hostNameII"
echo "Local Host: $localHostII"
if [[ "$computerNameII" == "$assetTag" ]] && [[ "$hostNameII" == "$assetTag" ]] && [[ "$localHostII" == "$assetTag" ]]
then
    echo "Computer Name satisfies naming standards"
    $DIV1; exit 0
else
    echo "Computer does not meet naming standards"
    echo "More troubleshooting will be necessary."
    $DIV1; exit 1
fi
 
#*=============================================================================
#* END OF SCRIPT
#*=============================================================================