Mass App Unscope Script

HenryOzsoy
New Contributor III

Hey fellow admins,

I'm in a situation every year where I need to un-scope anything and everything from all my mobile device apps in JSS. I put together a script that uses curl to do API calls and does the job. I thought I might share it f anyone else may need a similar task in their environment. Just change the JSS URL and credentials in the commands to suit yours.

#!/bin/bash
#Bash Script to un-scope all smart groups from all your apps
#The script does an API call to your JSS to retrieve and list all your app's ID's
#Takes this info and does an API update (PUT) through a bash loop removing all scoped smart groups from all your apps in JSS


# Find the IDs for the applications
IDs=$(curl -sku YourUserName:YourPassword -H "content-type: text/xml" https://YourJSSURL:8443/JSSResource/mobiledeviceapplications | xmllint --format - | awk -F '[<>]' '/<id>/{print $3}')



#Loop through the IDs in the variable and action a command for each of them
for idNumber in $IDs
do
curl -sku YourUserName:YourPassword -H "content-type: text/xml" https://YourJSSURL:8443/JSSResource/mobiledeviceapplications/id/$idNumber -X PUT -d "<mobile_device_application>
<scope>
        <all_mobile_devices>false</all_mobile_devices>
        <all_jss_users>false</all_jss_users>
        <mobile_devices/>
        <buildings/>
        <departments/>
        <mobile_device_groups/>
        <jss_users/>
        <jss_user_groups/>
        <limitations>
            <users/>
            <user_groups/>
            <network_segments/>
        </limitations>
        <exclusions>
            <mobile_devices/>
            <buildings/>
            <departments/>
            <mobile_device_groups>
                <mobile_device_group>
                    <id>41</id>
                    <name>Apple TVs</name>
                </mobile_device_group>
            </mobile_device_groups>
            <users/>
            <user_groups/>
            <network_segments/>
            <jss_users/>
            <jss_user_groups/>
        </exclusions>
    </scope>
</mobile_device_application>"
done
0 REPLIES 0