Matching AD Computer ID to Local Computer Name

yurypanasyuk
New Contributor III

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 2

joshuasee
Contributor III

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}

a_stonham
Contributor II

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;