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.
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
#*=============================================================================