Currently, we're using the below script that works with renaming our machines and randomising the machine's name.
#!/bin/bash
num="$((RANDOM % 9999))"
size=${#num}
toadd="$((6 - $size))"
for (( i=1; i<=toadd; i++))
do
num=0$num
done
compname=PREFIX-$num
if [ ${compname} ];
then
sudo scutil --set HostName $compname
sudo scutil --set ComputerName $compname
sudo scutil --set LocalHostName $compname
fi
echo $compname
Attempting to further improve this so machines do not end up with a duplicated name (no matter how small a chance!) there is.
Is there a way to do an inventory check for all machine names on Jamf Pro and then either a) add those numbers to an exclusion list so they're never chosen, or b) re-roll the randomiser section, after checking, if the name already exists?
How would the above be edited / shortened to make this a thing?
What possible improvements could be made to the above as well?
Any help is greatly appreciated !