Updating computer inventory Computer Names

pchrichard
Contributor

I'm running a bash script to update the computer name of our Macs dynamically based on a combination of the current user and our standard PC naming convention. This updates the computer name successfully, I can see this is reflected within systems preferences > sharing, but despite running a recon afterward, the new computer name isn't reflected in the JSS Computer inventory, it still says, for example, Pete's MacBook Pro.

Any ideas on how this field can be updated based on the new actual name of the device?

4 REPLIES 4

dandale
New Contributor

Post a copy of your script. We can start there and see if anything obvious needs to be modified in your coding.

dsavageED
Contributor III

When we set the computer name, our code does a recon to update the JSS, looks like:

  # Check name is right
  counter=0
  livename=`/usr/sbin/scutil --get ComputerName`
  until [ $livename == $name ]; do
    /usr/sbin/scutil --set LocalHostName "${name}"
    /usr/sbin/scutil --set ComputerName "${name}"
    /usr/sbin/scutil --set HostName "${name}"
    # Set the NetBIOS name
    defaults write /Library/Preferences/SystemConfiguration/com.apple.smb.server NetBIOSName -string "${name}"
    sleep 2
    livename=`/usr/sbin/scutil --get ComputerName`
        if [ "$counter" -gt 4 ]; then
            echo "Breaking loop and failing out as we cannot set the computer name"
        exit 0;
    fi
  done

  dscacheutil -flushcache

  echo "$0: Set machine name to ${name}"
  echo "$0: Updating JSS"
  /usr/local/bin/jamf recon -endUsername ${uun}

pchrichard
Contributor

Script is:

USERNAME=$(/usr/bin/python -c 'from SystemConfiguration import SCDynamicStoreCopyConsoleUser; import sys; username = (SCDynamicStoreCopyConsoleUser(None, None, None) or [None])[0]; username = [username,""][username in [u"loginwindow", None, u""]]; sys.stdout.write(username + " ");')

create network name using username and DA-prefix

netnameprefix=$"DA-"
netname=$"$netnameprefix$USERNAME"

set hostname and local hostname

sudo scutil --set HostName $netname
sudo scutil --set LocalHostName $netname
exit 0

Even after a jamf recon, nothing updates?

pchrichard
Contributor

I've got this working, was missing --setComputerName - it's this bit that the inventory must base itself off?