Skip to main content
Question

Matching AD Computer ID to Local Computer Name

  • February 15, 2017
  • 2 replies
  • 10 views

Forum|alt.badge.img+5

Hello,

I am trying to figure out how I can rename the local computer names (ComputerName, LocalHostName, and HostName) to the current Computer ID currently set by AD bind on machine using bash or AppleScript.

2 replies

Forum|alt.badge.img+17
  • Valued Contributor
  • February 15, 2017

Untested, but this should do the trick. Note that the name in AD has a trailing $ .

#!/bin/bash
ad_name=$(/usr/libexec/PlistBuddy -c 'Print ":General Info:Computer Account"' /dev/stdin <<< $(/usr/sbin/dsconfigad -show -xml))
/usr/local/jamf/bin/jamf setComputerName -name ${ad_name}

Forum|alt.badge.img+7
  • Contributor
  • February 16, 2017

This should do the trick.

#!/bin/bash
ADCOMPUTERNAME=`dsconfigad -show | grep "Computer Account" | awk '{print $4}' | cut -d '$' -f 1`;
if [ "$ADCOMPUTERNAME" == "" ]; then
    echo "Unable to determine computer name";
    exit 1;
fi

echo "Setting computer name to: $ADCOMPUTERNAME";

/usr/local/bin/jamf setComputerName -name $ADCOMPUTERNAME


exit 0;