Set computer name (inventory preload)

AdarioValHalen
New Contributor

Hi,

My entreprise and I are new with JamfPro.

We are trying to modify the computername during prestage enrollment.

In fact, we wants to use informations store in:

- inventory preload (information we configure in "bar code 1")

or

- inventory of the computer (but I don't know if the "bar code 1" information is availble when we want to use it)

But I don't know if it is possible.

Can you give help please?

 

2 REPLIES 2

dlbrabb
New Contributor III

Here's a script we use based upon the Barcode 1 in inventory preload.

 

Big Sur or newer:

#!/bin/bash

SERIAL_NUMBER=$(system_profiler SPHardwareDataType | awk '/Serial/ {print $4}')
JSS=https://COMPANYNAME.jamfcloud.com
API_USER="$4"
API_PASS="$5"
BARCODE_1_INFO=$(curl -k $JSS/JSSResource/computers/serialnumber/"$SERIAL_NUMBER" --user "$API_USER:$API_PASS" | xpath -e /computer/general/barcode_1 | awk '{gsub(/<[^>]*>/,"")};1')
SUFFIX=""

if [ -n "$BARCODE_1_INFO" ]; then
  echo "Processing new name for this client..."
  echo "Changing name..."
  /usr/sbin/scutil --set HostName "$BARCODE_1_INFO""$SUFFIX"
  /usr/sbin/scutil --set LocalHostName "$BARCODE_1_INFO""$SUFFIX"
  /usr/sbin/scutil --set ComputerName "$BARCODE_1_INFO""$SUFFIX"
  jamf -setComputerName -name "$BARCODE_1_INFO""$SUFFIX"
  echo "Name change complete "$BARCODE_1_INFO""$SUFFIX"

else
  echo "Bar code information was unavailable. Using Serial Number instead."
  echo "Changing Name..."
  /usr/sbin/scutil --set HostName "$SERIAL_NUMBER""$SUFFIX"
  /usr/sbin/scutil --set LocalHostName "$SERIAL_NUMBER""$SUFFIX"
  /usr/sbin/scutil --set ComputerName "$SERIAL_NUMBER""$SUFFIX"
  jamf -setComputerName -name "$SERIAL_NUMBER""$SUFFIX"
  echo "Name Change complete "$SERIAL_NUMBER""$SUFFIX"
fi

 

Catalina or older:

#!/bin/bash

SERIAL_NUMBER=$(system_profiler SPHardwareDataType | awk '/Serial/ {print $4}')
JSS=https://COMPANYNAME.jamfcloud.com
API_USER="$4"
API_PASS="$5"
BARCODE_1_INFO=$(curl -k $JSS/JSSResource/computers/serialnumber/"$SERIAL_NUMBER" --user "$API_USER:$API_PASS" | xpath /computer/general/barcode_1 | awk '{gsub(/<[^>]*>/,"")};1')
SUFFIX=""

if [ -n "$BARCODE_1_INFO" ]; then
  echo "Processing new name for this client..."
  echo "Changing name..."
  /usr/sbin/scutil --set HostName "$BARCODE_1_INFO""$SUFFIX"
  /usr/sbin/scutil --set LocalHostName "$BARCODE_1_INFO""$SUFFIX"
  /usr/sbin/scutil --set ComputerName "$BARCODE_1_INFO""$SUFFIX"
  jamf -setComputerName -name "$BARCODE_1_INFO""$SUFFIX"
  echo "Name change complete "$BARCODE_1_INFO""$SUFFIX"

else
  echo "Bar code information was unavailable. Using Serial Number instead."
  echo "Changing Name..."
  /usr/sbin/scutil --set HostName "$SERIAL_NUMBER""$SUFFIX"
  /usr/sbin/scutil --set LocalHostName "$SERIAL_NUMBER""$SUFFIX"
  /usr/sbin/scutil --set ComputerName "$SERIAL_NUMBER""$SUFFIX"
  jamf -setComputerName -name "$SERIAL_NUMBER""$SUFFIX"
  echo "Name Change complete "$SERIAL_NUMBER""$SUFFIX"
fi

  When creating the script, make sure that parameters 4 and 5 are your API_USER and API_PASSWORD. 

AdarioValHalen
New Contributor

Sorry, I was on holidays...

Thanks, I will try these scripts this week!