Skip to main content
Question

Updating computer inventory Computer Names


Forum|alt.badge.img+7

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

Forum|alt.badge.img+1
  • New Contributor
  • 1 reply
  • June 12, 2019

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


dsavageED
Forum|alt.badge.img+8
  • New Contributor
  • 169 replies
  • June 12, 2019

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}

Forum|alt.badge.img+7
  • Author
  • Contributor
  • 33 replies
  • June 12, 2019

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?


Forum|alt.badge.img+7
  • Author
  • Contributor
  • 33 replies
  • June 12, 2019

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


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings