Skip to main content
Question

Computer name

  • August 9, 2016
  • 29 replies
  • 157 views

Show first post

29 replies

Forum|alt.badge.img+8
  • Contributor
  • February 28, 2018

quedayone,

I like your script! I plan to run it through a self-service policy during my next deployment.

Cheers,

~B


Forum|alt.badge.img+8
  • Contributor
  • March 1, 2018

This is the script I used as part of a post image process. It checks to see if the model is a "MacBook" of any kind and stamps
either an "L" if so, or a "D" if not, to the file located in the following command.

touch /private/var/log/fv2.log

It then renames the machine with that letter + serial number. A post image policy checks that file and if an "L" is found it kicks off another policy that starts FileVault encryption. Use the whole thing, take bits and pieces or ignore all together and use one of the above fine methods. Perhaps it will help someone

Also don't forget. Aside from running the "scutil" command to change the name you also have to run:

defaults write /Library/Preferences/SystemConfiguration/com.apple.smb.server NetBIOSName

Or you will see a different name on the network than what the machine shows you at the terminal.

#!/bin/sh

# Name    : postImage0_SetComputerName.sh
# Author  : Snickasaurus
# Date    : 20141113
# Purpose : Set machine name and stamp fv2 file.

# Variables
theSerial=$(system_profiler SPHardwareDataType | awk '/Serial/ {print $4}')
theModel=$(system_profiler SPHardwareDataType | grep 'Model Name:' | awk '{ print $3 }')

# Logging
exec 3>&1 4>&2
trap 'exec 2>&4 1>&3' 0 1 2 3
exec 1>>/private/var/log/postImage0-"$(date "+%Y%m%d-%H%M%S")".log 2>&1

# Begin script
touch /private/var/log/fv2.log

# Echo the current name settings to the log file.
echo "-----"
echo "-"
echo "-"
echo "Current ComputerName is: $(scutil --get ComputerName)"
echo "Current HostName is: $(scutil --get HostName)"
echo "Current LocalHostName is: $(scutil --get LocalHostName)"
echo "Current NetBIOSName is: $(defaults read /Library/Preferences/SystemConfiguration/com.apple.smb.server NetBIOSName)"
echo "-"
echo "-"
echo "-----"

# Check for the model type and set it's name accordingly.
if [[ "$theModel" == "MacBook" ]]
    then
    scutil --set ComputerName "L$theSerial"
    scutil --set HostName "L$theSerial"
    scutil --set LocalHostName "L$theSerial"
    defaults write /Library/Preferences/SystemConfiguration/com.apple.smb.server NetBIOSName "L$theSerial"
    echo "L" > /private/var/log/fv2.log
else
    echo "D" > /private/var/log/fv2.log
    scutil --set ComputerName "D$theSerial"
    scutil --set HostName "D$theSerial"
    scutil --set LocalHostName "D$theSerial"
    defaults write /Library/Preferences/SystemConfiguration/com.apple.smb.server NetBIOSName "D$theSerial"
fi

# Space out the name lines.
echo " "
echo " "

# Echo the new name settings to the log file.
echo "-----"
echo "-"
echo "-"
echo "New ComputerName is: $(scutil --get ComputerName)"
echo "New HostName is: $(scutil --get HostName)"
echo "New LocalHostName is: $(scutil --get LocalHostName)"
echo "New NetBIOSName is: $(defaults read /Library/Preferences/SystemConfiguration/com.apple.smb.server NetBIOSName)"
echo "-"
echo "-"
echo "-----"

exit 0

easyedc
Forum|alt.badge.img+16
  • Esteemed Contributor
  • March 1, 2018

Since this thread is getting bumped, Is anyone having issues with having a single script and HS/APFS/Fusion Drives? My script works when run locally, but does not work when run by my JSS a policy.

#!/bin/bash

base="MK"
serial=$(/usr/sbin/system_profiler SPHardwareDataType | /usr/bin/awk '/Serial Number (system)/ {print $NF}')
/usr/sbin/scutil --set ComputerName "${base}${serial}"
/usr/sbin/scutil --set LocalHostName "${base}${serial}"
/usr/sbin/scutil --set HostName "${base}${serial}"

APFS=$(/usr/sbin/diskutil list | grep "APFS")
Apple_HFS=$(/usr/sbin/diskutil list | grep "Apple_HFS")
Fusion=$(/usr/sbin/diskutil list | grep "virtual")

if [ "$APFS" != "" ]; then
diskutil rename disk1s1 "${base}${serial}"
elif [ "$Apple_HFS" != "" ]; then
diskutil rename disk0s2 "${base}${serial}"
elif [ "$Fusion" != "" ]; then
diskutil rename disk2 "${base}${serial}"
fi

Forum|alt.badge.img+3
  • New Contributor
  • April 19, 2018

I'm not seeing the "Update Inventory" option under Maintenance, or "jamf recon" put in under Execute command in Files and Processes actually work as stated in this thread. The logs indicate recon is run, however the name of the computer in JAMF never updates. The result is rather disastrous at this point as it is causing names to not only be out of sync, but get broken by another policy that should fix names that are not right. It's critical that JAMF show the proper name of a device so that smart groups work accurately, we need a solution for this.

This is compounding the frustration that JAMF completely lacks the ability to name a DEP placeholder and therefore have the proper name pushed to the machine at enrollment. Profile Manager does this, baffling that JAMF can't. As a result, we have a script run at enrollment that names the machine based on DNS lookup. Works fine. However, JAMF then fails to ever get this name from the device. A second policy renames machines to their record name if they don't match a convention in a smart group. This is designed so that if DNS is not correct at enrollment, we can correct the name manually in the console, it will push down to the machine. Because JAMF is not updating the record properly, the policy is pushing generic names down to machines that have proper names. It's a real mess, and I can't figure out how something so basic, and critical to AD binding, is so severely lacking. Directory binding at enrollment is impossible since pre-stage devices can't be named (so why have a feature that can't be used?), and naming past that seems entirely unreliable.