Executed Command result to new account username?

nihgreggm
New Contributor

Hi everyone, I'm loving the resources here but I can't seem to find anything on this.
Using a policy, is it possible to create a local user with a username taken from results of an executed command in the 'Files and Processes' section? I see in the logs that my command is working and giving me the result I want, but I can't figure out how to get the results useable in the 'Local Accounts' section.

1 ACCEPTED SOLUTION

mm2270
Legendary Contributor III

While I don't think its possible to pass the results from Execute Command to another section of a policy, you should look at the jamf binary help page. You can create accounts using a jamf binary verb createAccount, so you'd be able to pass the variable to a jamf command.

For example, run jamf help createAccount to see the information on creating an account with the jamf binary.

I don't know what you're putting into the Execute Command field, but you can store that in a variable and string two or more commands together there. For example

username=$(your command goes here); /usr/local/bin/jamf createAccount -username "$username" -realname "Some Body" -admin

The above would take your command, store it as a variable called "username", then use that with the jamf binary to use it as the source for the shortname. Separating the 2 commands with a ; is how to string them together in the single Execute Command field.

Anything more complicated than the above I would look at using a full script instead of Execute Command.

View solution in original post

2 REPLIES 2

mm2270
Legendary Contributor III

While I don't think its possible to pass the results from Execute Command to another section of a policy, you should look at the jamf binary help page. You can create accounts using a jamf binary verb createAccount, so you'd be able to pass the variable to a jamf command.

For example, run jamf help createAccount to see the information on creating an account with the jamf binary.

I don't know what you're putting into the Execute Command field, but you can store that in a variable and string two or more commands together there. For example

username=$(your command goes here); /usr/local/bin/jamf createAccount -username "$username" -realname "Some Body" -admin

The above would take your command, store it as a variable called "username", then use that with the jamf binary to use it as the source for the shortname. Separating the 2 commands with a ; is how to string them together in the single Execute Command field.

Anything more complicated than the above I would look at using a full script instead of Execute Command.

nihgreggm
New Contributor

Great work around. Thank you!