Script Lookup/Dynamic Parameters

pmeyer
New Contributor

Hey all,

I see that when running scripts, the first three parameters ($1-$3) are mount point, computer name, and username. I also see that I could enter additional parameters when running the script. Can those parameters be a lookup/dynamic instead of static information? Such as, pull an attribute from the Jamf asset for each asset it runs on?

Say you want to update hostnames based on <username>-<serial> but the local username is spelled wrong or non-conforming. I want the username it pulls to be from the asset's assigned user's username, not the local computer's username. So in parameter 4 I'd like to put in something like "JamfAsset.AssignedUser.Username" so for each asset this script runs on it enters the correctly assigned username.

My alternatives I can think of so far are to either exclude the exceptions from the policy and manually manage their hostnames, or find a way to actively correct their local usernames (which can lead to a whole host of additional problems).

Any thoughts on if this is possible or if I'm approaching this wrong?

Thank you in advance!!
PJ

2 REPLIES 2

mm2270
Legendary Contributor III

While I don't think it's possible to use a parameter that will automatically know the device information you're looking for and substitute it, you can get this information using the API. In your script, you would need to use an API call against the Jamf console for the device the script is running on to pull some values, and then use those as variables in the script to set up the name properly.

Hopefully that makes some sense. If you've never used the Jamf API before and need some pointers, post back. Whether its me or someone else, someone will probably post an example script on how to do it.

pmeyer
New Contributor

Ahhh, thanks @mm2270 , I've just started to explore the API and, with a couple lookups, I think I can achieve what I need to here.

Thank you!