Posted on 09-10-2019 02:00 PM
This is what I have now, just looking for guidance on making this work
#!/bin/sh
username=`ls -l /dev/console | cut -d " " -f 4`
scutil --set ComputerName "$4""$username"
scutil --set HostName "$4""$username".domain
scutil --set LocalHostName "$4""$username"
jamf recon
If I execute this script from terminal following results:
SCPreferencesSetLocalHostName() failed: Invalid argument
I can run following lines, line by line fine all is good.
scutil --set ComputerName whateverUsername
scutil --set HostName whateverUsername.domain
scutil --set LocalHostName whateverUsername
Any suggestions?
Solved! Go to Solution.
Posted on 09-10-2019 02:36 PM
ignore works as expected through jamfpro if we push, but not if we execute script manually from macos.
Posted on 09-10-2019 02:36 PM
ignore works as expected through jamfpro if we push, but not if we execute script manually from macos.
Posted on 09-10-2019 03:27 PM
That’s because $4 are Jamf variables, which terminal app doesn’t know anything about.
Posted on 09-12-2019 12:22 AM
This is our solution and it works well.
#!/bin/bash
# Enter the API Username, API Password and JSS URL here
apiuser="your-api-read-only-user" # create a user for read only (Active Directory or local on Jamf Server)
apipass="your-password" # password for the api-read-only
jssURL="https://your.jamfserver-url:8443"
# Get the Mac's UUID string
UUID=$(ioreg -rd1 -c IOPlatformExpertDevice | awk -F'"' '/IOPlatformUUID/{print $4}')
# Make first a "Inventory Preload" with Asset Tag (Settings > Global Management)
# Pull the Asset Tag by accessing the computer records "general" subsection
Asset_Tag=$(curl -H "Accept: text/xml" -sfku "${apiuser}:${apipass}" "${jssURL}/JSSResource/computers/udid/${UUID}/subset/general" | xmllint --format - 2>/dev/null | awk -F'>|<' '/<asset_tag>/{print $3}')
echo "$Asset_Tag"
scutil --set ComputerName "$Asset_Tag"
scutil --set HostName "$Asset_Tag"
scutil --set LocalHostName "$Asset_Tag"
# Make first a policy with a trigger for update-inventory
# Computers > Policies > General > General (Display Name: Update Inventory)
# Computers > Policies > General > Trigger (Custom Event: update-inventory)
# Computers > Policies > Maintenance > Update inventory
/usr/local/jamf/bin/jamf policy -trigger update-inventory
exit 0
Posted on 09-12-2019 05:08 AM
@ esv
username=ls -l /dev/console | cut -d " " -f 4
scutil --set ComputerName "$4""$username"
scutil --set HostName "$4""$username".domain
scutil --set LocalHostName "$4""$username"
jamf recon
your above script works fine, But also the machines are getting removed from AD. I wanted the machines to be rename in AD as well is there any way for this.
Posted on 09-12-2019 05:45 AM
@vijayragesh We name ours differently but the unbind - bind should work for you. We trigger a policy to bind call the trigger in the rename script. I have several bind policies based on the device use. Otherwise you would need to run dsconfigad -add -force -u "${username}" -p "${password}"
username="xxxxxx" password="*xxxxxx"
dsconfigad -remove -force -u "${username}" -p "${password}"
scutil --set ComputerName $computername
scutil --set LocalHostName $computername
scutil --set HostName $computername
jamf policy -trigger bind_to_ad
Hope this helps
Posted on 03-23-2022 02:51 PM
"dsconfigad -remove..." actually removes the AD record, which may be required in some environments depending on how Active Directory is setup in regards to the login used to bind with.
In my environment I can get away with "dsconfig -leave -force" That way I'm not putting AD login details into a script, and the rebind automatically reconnects to the same AD record and corrects the name.
Posted on 09-28-2023 02:23 AM
This is failing because the username contains a dot. For my environment, I can do without it since I am not going to be remotely connecting to the devices