Posted on 02-10-2021 09:39 AM
So, I've asked this question before and received some excellent help from sharrison (https://www.jamf.com/jamf-nation/discussions/37206/set-new-computer-name-and-update-in-jamf-pro). Thanks again!
But I'm looking to refine it a bit, and I think my solution is through the Trigger.
My script:
username=$(/usr/bin/osascript<<END
tell application "System Events"
activate
set the answer to text returned of (display dialog "Please enter the computer name" default answer "" buttons {"Rename"} default button "Rename")
end tell
END)
echo $username
/usr/local/bin/jamf setcomputername -name $username
/usr/local/bin/jamf recon
I want it to run when I click a button in Self Service. Not just show up as an ongoing or recurring event, but always be available.
Right now, to make it available in Self Service makes the Rename box created in the script always pop up (see pic). I just want it to pop up when I click the "Change Name/Change Again" button is clicked.
Thoughts?
Posted on 02-11-2021 07:18 AM
Can you clarify this?
Do you have this policy running automatically with a trigger such as login or recurring check-in?
AND
in Self Service?
If you want this to be presented through Self Service only, you would want it as a separate policy.
Self Service tab:
check Make ths policy available in Self Service
Options tab:
No triggers,
Execution Frequency: ongoing (if you want to be able to rerun the policy), or set to one time (and flush the log for this policy for that specific computer, or group, or all).
Posted on 05-12-2022 02:09 PM
Were you able to get this working? Would really like to use this. As our machines are set up to have a specific hostname so certain applications and settings are applied. Would be nice as soon as the machine is registered and we are logged in we could just click on the computer name change in self serve and change the name rite away with a prompt.
We were doing it the other way which was to edit the name in jAMF and then click on a policy that was created by a prior IT person. But the policy is disappearing on us and not even changing the hostname anymore.
Posted on 05-16-2022 10:53 AM
@dpwlg Yes we have. Actually we have built 4 ways to change the laptop names.
1. Enrollment - We change all computer names to their Serial upon enrollment. Have a policy with this script:
#!/usr/bin/env bash
# Get the Serial Number of the Machine
sn=$(system_profiler SPHardwareDataType | awk '/Serial/ {print $4}')
# Set the ComputerName, HostName and LocalHostName
scutil --set ComputerName $sn
scutil --set HostName $sn
scutil --set LocalHostName $sn
2. Newly Enrolled Computers - Because we get a huge stack of laptops and then slowly move them out as upgrades we need a way to change names on the fly. This policy is scoped to a Smart group based on Computer Name with the value being the first 3 letters of the serials we named them above. It runs this script:
#!/bin/bash
username=$(/usr/bin/osascript<<END
tell application "System Events"
activate
set the answer to text returned of (display dialog "Please enter the computer name" default answer "" buttons {"Rename"} default button "Rename")
end tell
END)
echo $username
/usr/local/bin/jamf setcomputername -name $username
/usr/local/bin/jamf recon
That allows me, through Self Service to activate/install this policy and change it on the fly.
3. Available Computers - We manage elementary, middle and high schools so each cohort has different needs regarding apps, printers, etc. Rather than waiting to see who will get the laptop and then installing the needed stuffs, we'll parse out newly enrolled laptops in to the 3 stacks and name them after their asset ID with an amendment of "-avail". The we scope then same script used in 2 and aim it at the smart group, so we can change the laptop's name again when we know who will be getting it.
4. Remote Name Change - when we cannot get our grubby little hands on the actual machine but need to change the name I built a recurring auto install name change policy. Script is simple:
#!/bin/bash
ComputerName="$4"
scutil --set HostName $ComputerName
scutil --set LocalHostName $ComputerName
scutil --set ComputerName $ComputerName
For the script, under Options, we adjusted Parameter 4 to "Type Computer Name Here". In the actual policy you'd type in what you want the remote laptop's name to be.
So when one of these instances come up I'd clone the original, scope to the laptop in question, adjust parameter 4 and then wait and check when name has changed in Jamf and delete the policy.
Seems like too many options but we are a small shop and have to handle bunches of weird situation. these seem to cover all the current bases.
Take a look and let me know if you have any further questions.
- Kevin Neely
Posted on 05-16-2022 04:22 PM
This is awesome. Appreciate sharing will definitely try this out any questions will be reaching out. :)