Schedule Policy

KyleEricson
Valued Contributor II

Is there a way to schedule a policy to run? I'm using DEP Notify and at the end of my DEP Notify setup the machine reboots. I would like to have the DEP Start script run a policy so that when the user logs in it runs the policy with a delay until they are actually logged in . I have tried the trigger login, but it doesn't seem to work correctly since it's doing the Intune Azure registration via MS Company Portal.

Read My Blog: https://www.ericsontech.com
4 REPLIES 4

mm2270
Legendary Contributor III

Check for the Dock running in whatever script is calling your policy, and then fire off whatever it is you need after it sees it.
I'm not sure if your start script is actually running the DEP stuff or if it's just calling some other policies, but either way, you can include a loop in the script that it will remain in until it sees the Dock process running.

If you need an example of how to do this, there are a few existing scripts out there that do this. I can point you to one, or just post example code if needed.

KyleEricson
Valued Contributor II

@mm2270 Yeah an example would be great. If I do the loop I could just call the policy with a trigger at that point.

Read My Blog: https://www.ericsontech.com

mm2270
Legendary Contributor III

@kericson Here's a code snippet from one of my scripts. It's not a complete script of course. But you can incorporate something like this into your existing script. Your code to execute the policies would come after the loop exits, so after where it says echo "Dock is running. Continuing the script..."

## Value in seconds for the script to wait before checking again
SLEEP_SECS="3"

## Loop every 3 seconds until the Dock is running (indicates login of user account)
until [[ $(ps axc | grep "Dock" 2>&1 > /dev/null; echo $?) == 0 ]]; do
    echo "Waiting $SLEEP_SECS seconds for the Dock to be running"
    sleep $SLEEP_SECS
done

## Once we exit the loop, the Dock is running
echo "Dock is running. Continuing the script..."

Hope that helps. Post back if you run into any issues with it.

KyleEricson
Valued Contributor II

@mm2270 What about a script that will not run if this user(local staging account) is logged in?

Read My Blog: https://www.ericsontech.com