Remember that time you wanted all of your Self Service display names to actually match your policy names?

brockwalters
Contributor II

You may never want this because your policy names match some convention, or your Self Service display names do, or, whatever. This is just a good find & replace technique for labels in Jamf that can be used pretty much anywhere.

Anyway, Jamf Nation, I hope someone finds this useful. Enjoy!

#!/bin/bash

apipsw=''
apiurl=''
apiusr=''

# get the object id for every Policy
policyids=($(/usr/bin/curl -k -s -S -H "Accept: application/xml" -u "$apiusr:$apipsw" "$apiurl/policies" | /usr/bin/xmllint -xpath "//policies/policy/id" - | /usr/bin/tr '</id>' ' ')); /bin/sleep 1

# for each Policy check if Self Service is enabled
for x in "${policyids[@]}" do
selfservice=$(/usr/bin/curl -k -s -S -H "Accept: application/xml" -u "$apiusr:$apipsw" "$apiurl/policies/id/$x" | /usr/bin/xmllint -xpath "//policy/self_service/use_for_self_service/text()" -); /bin/sleep 1

# if Self Service is enabled get the Policy Display Name label from Jamf Pro UI

if [ "$selfservice" = true ] then
echo "id $x is a Self Service Policy"
displayname=$(/usr/bin/curl -k -s -S -H "Accept: application/xml" -u "$apiusr:$apipsw" "$apiurl/policies/id/$x" | /usr/bin/xmllint -xpath "//policy/general/name/text()" -); /bin/sleep 1

# change the Self Service Policy Display Name to the Jamf Pro Display Name

/usr/bin/curl -k -s -S -X PUT -H "Content-type: application/xml" -d "<policy><self_service><self_service_display_name>$displayname</self_service_display_name></self_service></policy>" -u "$apiusr:$apipsw" "$apiurl/policies/id/$x"
echo "Self Service display name set to: $displayname"; echo
fi done
0 REPLIES 0