Send Blank Push Command to All Devices

Lessardrp
Contributor

Sometimes when an app or profile is scoped to devices, they get stuck in a pending status indefinitely, but a blank push command will "wake up" the process and it will complete. I'd like a way to send a blank push to all devices if a major profile or app gets deployed to speed up distribution.

I can pull up a smart group of managed devices, go into the action menu and send commands to the group, but sending a blank push is not an option as a remote command using this method. And I'm not interested in doing it on an individual device basis from the management menu.

Is there a way to send a blank push remote command to all devices or a group of devices?

Thanks,

Rob 

1 REPLY 1

Steven_Xu
Contributor

Try this scipt. Save as .sh file and run it in terminal, should work for you.

#!/bin/bash
# Created by Steven Xu on Dec. 10, 2022
# https://community.jamf.com/t5/user/viewprofilepage/user-id/41850
###################################################################
########### Modify the following parameters to fit your task  #####    
###################################################################

# your jss url
jss_url="https://xxxx.jamfcloud.com"

# Mobile device group id. Open the group in Jamf Pro and find the id in the browser url.
mgroup_id="19"

# Remote command action. 
# Supported command: https://developer.jamf.com/jamf-pro/reference/createmobiledevicecommandurl
command="BlankPush"

###################################################################
############     Don't modify from here              ##############
###################################################################

echo "Please login to your Jamf Pro Server: $jss_url"
read -p "Your account username: " api_user
stty -echo
read -p "Your password: " api_pass
stty -echo
echo

# Get authToken
authToken=$(curl -s -u "${api_user}:${api_pass}" "$jss_url/api/v1/auth/token" -X POST -H "accept: application/json" )
bearerToken=$(echo "$authToken" | plutil -extract token raw -)

# Token validation check
valid_check=$(curl -s -H "Authorization: Bearer ${bearerToken}" "$jss_url/api/v1/jamf-pro-version" -X GET | plutil -extract version raw -)
if [[ "$valid_check" == *error* ]]; then
	echo Get the token failed, try the correct username and password.
	exit 1
fi

# Get mobile device IDs from  the mobile device group. 
ids=`curl -ksu "$api_user:$api_pass" -X GET "$jss_url/JSSResource/mobiledevicegroups/id/$mgroup_id" -H "accept: application/xml" \
| xmllint --format --xpath /mobile_device_group/mobile_devices/mobile_device/id - | sed 's/<id>//g' | sed 's/<\/id>/,/g' | rev | sed 's/,//' | rev`

if [ -z "$ids" ]; then
    echo "no devices in this group"
    exit 0
	else 
	echo "Mobile device IDs in this groups: $ids"
fi

# Send command to the mobile devices
for id in $ids 
do 
	echo "Sending $command to device id: $id..."
	/usr/bin/curl \
     --header "Authorization: Bearer ${bearerToken}" \
     --request POST \
     --header "Content-Type: application/xml" \
     --url "${jss_url}/JSSResource/mobiledevicecommands/command/${command}/id/${id}"
	echo "\n"
done

# Set the token invalid
/usr/bin/curl \
     --header "Authorization: Bearer ${bearerToken}" \
     --request POST \
     --silent \
     --url "${jss_url}/api/v1/auth/invalidate-token"
echo "Done."