Skip to content

Instantly share code, notes, and snippets.

@stevewood-tx
Created August 11, 2022 15:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stevewood-tx/0874c23c002c98488283526dd6532f0a to your computer and use it in GitHub Desktop.
Save stevewood-tx/0874c23c002c98488283526dd6532f0a to your computer and use it in GitHub Desktop.
Update Policies via API
#!/bin/bash
args=("$@")
jssAPIUsername=''
jssAPIPassword=''
jssAddress=""
file="${args[0]}"
#Verify we can read the file
data=`cat $file`
if [[ "$data" == "" ]]; then
echo "Unable to read the file path specified"
echo "Ensure there are no spaces and that the path is correct"
exit 1
fi
computerqty=`awk -F, 'END {printf "%s\n", NR}' $file`
counter="0"
while [ $counter -lt $computerqty ]
do
counter=$[$counter+1]
line=`echo "$data" | head -n $counter | tail -n 1`
policyID=`echo "$line" | awk -F , '{print $1}'`
#groupID=`echo "$line" | awk -F , '{print $2}'`
#category=`echo "$line" | awk -F , '{print $3}'`
#installTrigger=`echo "$line" | awk -F , '{print $4}'`
#ssDisplayName=`echo "$line" | awk -F , '{print $5}'`
#ssDescription=`echo "$line" | awk -F , '{print $6}'`
#ssIcon=`echo "$line" | awk -F , '{print $7}'`
echo $policyID
xml="<policy>\
<package_configuration>\
<packages>\
<size>1</size>\
<package>\
<id>1804</id>\
<name>DEPNotify-1.1.4-20190521.pkg</name>\
<action>Install</action>\
<fut>false</fut>\
<feu>false</feu>\
<update_autorun>false</update_autorun>\
</package>\
</packages>\
</package_configuration>\
</policy>"
output=`curl -ku ${jssAPIUsername}:${jssAPIPassword} "$jssAddress/JSSResource/policies/id/${policyID}" -X PUT -H "Content-Type: text/xml" -d "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>$xml"`
done
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment