Created
August 11, 2022 15:15
-
-
Save stevewood-tx/0874c23c002c98488283526dd6532f0a to your computer and use it in GitHub Desktop.
Update Policies via API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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